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

View file

@ -57,7 +57,7 @@ public class ImageLoader implements Callable<ResourceLocation> {
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));
return conv;
}

View file

@ -12,6 +12,7 @@ import java.util.concurrent.Future;
import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import com.google.common.collect.Maps;
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.minecraft.MinecraftProfileTexture.Type;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IResource;
@ -89,30 +91,45 @@ public class SkinResourceManager implements IResourceManagerReloadListener {
Skin skin = getSkin(profile);
if (skin != null) {
final ResourceLocation res = skin.getTexture();
if (res != null) {
if (this.inProgress.get(res) == null) {
// read and convert in a new thread
final ListenableFuture<ResourceLocation> conv = executor.submit(new ImageLoader(res));
conv.addListener(new Runnable() {
@Override
public void run() {
try {
converted.put(res, conv.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}, executor);
this.inProgress.put(res, conv);
}
}
return converted.get(res);
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 (this.inProgress.get(res) == null) {
// read and convert in a new thread
final ListenableFuture<ResourceLocation> conv = executor.submit(new ImageLoader(res));
conv.addListener(new Runnable() {
@Override
public void run() {
try {
if (!conv.isCancelled())
converted.put(res, conv.get());
} catch (Exception e) {
LogManager.getLogger().warn("Errored while processing " + res + ". Using original.", e);
converted.put(res, res);
}
}
}, executor);
this.inProgress.put(res, conv);
}
}
}
@Nullable
private Skin getSkin(GameProfile profile) {
Skin skin = this.uuidSkins.get(profile.getId());

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.LayerPonyArmor;
import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull;
import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.model.ModelBiped.ArmPose;
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.ItemStack;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
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() {
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
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);
if (loc == null)
loc = PonyManager.SKELETON;
return loc;
return getTexture(loc);
}
}

View file

@ -27,7 +27,7 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
this.shadowSize = 0.5F;
}
}
((ModelVillagerPony)this.mainModel).profession = villager.getProfession();
((ModelVillagerPony) this.mainModel).profession = villager.getProfession();
GlStateManager.scale(0.9375F, 0.9375F, 0.9375F);
}
@ -35,6 +35,6 @@ public class RenderPonyVillager extends RenderPonyMob<EntityVillager> {
@Override
protected ResourceLocation getEntityTexture(EntityVillager 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);
// races
switch (rand.nextInt(2)+2) {
switch (rand.nextInt(2) + 2) {
case 0:
case 1:
this.playerModel.getModel().metadata.setRace(PonyRace.EARTH);
@ -77,7 +77,7 @@ public class RenderPonyZombie extends RenderPonyMob<EntityZombie> {
if (loc == null) {
loc = zombie.isVillager() ? PonyManager.ZOMBIE_VILLAGER : PonyManager.ZOMBIE;
}
return loc;
return getTexture(loc);
}
}