Convert entity resource textures.

This commit is contained in:
Matthew Messinger 2016-09-07 23:53:23 -04:00
parent 72a6387397
commit 130c927780
8 changed files with 57 additions and 27 deletions

View file

@ -9,6 +9,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -257,6 +259,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
skinModifiers.add(modifier); skinModifiers.add(modifier);
} }
@Nullable
public ResourceLocation getConvertedSkin(@Nullable ResourceLocation res) {
return resources.getConvertedResource(res);
}
public void convertSkin(BufferedImage image, Graphics dest) { public void convertSkin(BufferedImage image, Graphics dest) {
for (ISkinModifier skin : skinModifiers) { for (ISkinModifier skin : skinModifiers) {
skin.convertSkin(image, dest); skin.convertSkin(image, dest);

View file

@ -57,7 +57,7 @@ public class ImageLoader implements Callable<ResourceLocation> {
private ResourceLocation loadSkin(BufferedImage image) { private ResourceLocation loadSkin(BufferedImage image) {
ResourceLocation conv = new ResourceLocation("hdskins-converted", original.getResourcePath()); ResourceLocation conv = new ResourceLocation(original.getResourceDomain() + "-converted", original.getResourcePath());
this.mc.getTextureManager().loadTexture(conv, new DynamicTextureImage(image)); this.mc.getTextureManager().loadTexture(conv, new DynamicTextureImage(image));
return conv; return conv;
} }

View file

@ -12,6 +12,7 @@ import java.util.concurrent.Future;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -22,6 +23,7 @@ import com.google.gson.JsonParseException;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResource;
@ -89,6 +91,24 @@ public class SkinResourceManager implements IResourceManagerReloadListener {
Skin skin = getSkin(profile); Skin skin = getSkin(profile);
if (skin != null) { if (skin != null) {
final ResourceLocation res = skin.getTexture(); final ResourceLocation res = skin.getTexture();
return getConvertedResource(res);
}
return null;
}
/**
* Convert older resources to a newer format.
*
* @param res The skin resource to convert
* @return The converted resource
*/
@Nullable
public ResourceLocation getConvertedResource(@Nullable ResourceLocation res) {
loadSkinResource(res);
return converted.get(res);
}
private void loadSkinResource(@Nullable final ResourceLocation res) {
if (res != null) { if (res != null) {
if (this.inProgress.get(res) == null) { if (this.inProgress.get(res) == null) {
// read and convert in a new thread // read and convert in a new thread
@ -97,20 +117,17 @@ public class SkinResourceManager implements IResourceManagerReloadListener {
@Override @Override
public void run() { public void run() {
try { try {
if (!conv.isCancelled())
converted.put(res, conv.get()); converted.put(res, conv.get());
} catch (InterruptedException e) { } catch (Exception e) {
e.printStackTrace(); LogManager.getLogger().warn("Errored while processing " + res + ". Using original.", e);
} catch (ExecutionException e) { converted.put(res, res);
e.printStackTrace();
} }
} }
}, executor); }, executor);
this.inProgress.put(res, conv); this.inProgress.put(res, conv);
} }
} }
return converted.get(res);
}
return null;
} }
@Nullable @Nullable

View file

@ -10,6 +10,7 @@ import com.brohoof.minelittlepony.model.PlayerModel;
import com.brohoof.minelittlepony.renderer.layer.LayerHeldPonyItem; import com.brohoof.minelittlepony.renderer.layer.LayerHeldPonyItem;
import com.brohoof.minelittlepony.renderer.layer.LayerPonyArmor; import com.brohoof.minelittlepony.renderer.layer.LayerPonyArmor;
import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull; import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull;
import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.model.ModelBiped.ArmPose; import net.minecraft.client.model.ModelBiped.ArmPose;
import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.client.renderer.entity.RenderLiving;
@ -18,6 +19,7 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.item.EnumAction; import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHandSide; import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving<T> implements IRenderPony { public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving<T> implements IRenderPony {
@ -105,4 +107,8 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
public PlayerModel getPony() { public PlayerModel getPony() {
return playerModel; return playerModel;
} }
protected ResourceLocation getTexture(ResourceLocation res) {
return HDSkinManager.INSTANCE.getConvertedSkin(res);
}
} }

View file

@ -15,7 +15,7 @@ public class RenderPonyPigman extends RenderPonyMob<EntityPigZombie> {
@Override @Override
protected ResourceLocation getEntityTexture(EntityPigZombie entity) { protected ResourceLocation getEntityTexture(EntityPigZombie entity) {
return PonyManager.PIGMAN; return getTexture(PonyManager.PIGMAN);
} }
} }

View file

@ -63,6 +63,6 @@ public class RenderPonySkeleton extends RenderPonyMob<EntitySkeleton> {
ResourceLocation loc = PonyManager.SKELETONS.get(type); ResourceLocation loc = PonyManager.SKELETONS.get(type);
if (loc == null) if (loc == null)
loc = PonyManager.SKELETON; loc = PonyManager.SKELETON;
return loc; return getTexture(loc);
} }
} }

View file

@ -27,7 +27,7 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
this.shadowSize = 0.5F; this.shadowSize = 0.5F;
} }
} }
((ModelVillagerPony)this.mainModel).profession = villager.getProfession(); ((ModelVillagerPony) this.mainModel).profession = villager.getProfession();
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F); GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
} }
@ -35,6 +35,6 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
@Override @Override
protected ResourceLocation getEntityTexture(EntityVillager villager) { protected ResourceLocation getEntityTexture(EntityVillager villager) {
Pony aVillagerPony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(villager); Pony aVillagerPony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(villager);
return aVillagerPony.getTextureResourceLocation(); return getTexture(aVillagerPony.getTextureResourceLocation());
} }
} }

View file

@ -28,7 +28,7 @@ public class RenderPonyZombie extends RenderPonyMob<EntityZombie> {
this.playerModel.getModel().metadata.setGender(rand.nextBoolean() ? PonyGender.MARE : PonyGender.STALLION); this.playerModel.getModel().metadata.setGender(rand.nextBoolean() ? PonyGender.MARE : PonyGender.STALLION);
// races // races
switch (rand.nextInt(2)+2) { switch (rand.nextInt(2) + 2) {
case 0: case 0:
case 1: case 1:
this.playerModel.getModel().metadata.setRace(PonyRace.EARTH); this.playerModel.getModel().metadata.setRace(PonyRace.EARTH);
@ -77,7 +77,7 @@ public class RenderPonyZombie extends RenderPonyMob<EntityZombie> {
if (loc == null) { if (loc == null) {
loc = zombie.isVillager() ? PonyManager.ZOMBIE_VILLAGER : PonyManager.ZOMBIE; loc = zombie.isVillager() ? PonyManager.ZOMBIE_VILLAGER : PonyManager.ZOMBIE;
} }
return loc; return getTexture(loc);
} }
} }