Improve armor layer. Should support modded armor now.

pony armor textures go in modid:textures/entity/armor/custom_armor_1_pony.png
This commit is contained in:
Matthew Messinger 2015-11-17 00:21:53 -05:00
parent f0509fbb28
commit 778630c6b5

View file

@ -43,21 +43,16 @@ public class LayerPonyArmor implements LayerRenderer {
} }
@Override @Override
public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float p_177141_2_, float p_177141_3_, public void doRenderLayer(EntityLivingBase entity, float p_177141_2_, float p_177141_3_, float ticks,
float partialTicks, float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) { float p_177141_5_, float p_177141_6_, float p_177141_7_, float scale) {
pony = ((IRenderPony) renderer).getPony(); pony = ((IRenderPony) renderer).getPony();
if (pony.model instanceof pm_Human) { if (pony.model instanceof pm_Human) {
humanArmor.doRenderLayer(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, humanArmor.doRenderLayer(entity, p_177141_2_, p_177141_3_, ticks, p_177141_5_, p_177141_6_, p_177141_7_,
p_177141_6_, p_177141_7_, scale); scale);
} else { } else {
renderArmor(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, for (int i = 4; i > 0; i--) {
p_177141_7_, scale, 4); renderArmor(entity, p_177141_2_, p_177141_3_, ticks, p_177141_5_, p_177141_6_, p_177141_7_, scale, i);
renderArmor(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_, }
p_177141_7_, scale, 3);
renderArmor(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_,
p_177141_7_, scale, 2);
renderArmor(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks, p_177141_5_, p_177141_6_,
p_177141_7_, scale, 1);
} }
} }
@ -67,12 +62,15 @@ public class LayerPonyArmor implements LayerRenderer {
if (itemstack != null && itemstack.getItem() instanceof ItemArmor) { if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
ItemArmor itemarmor = (ItemArmor) itemstack.getItem(); ItemArmor itemarmor = (ItemArmor) itemstack.getItem();
boolean isLegs = armorSlot == 3;
ModelPony modelbase = armorSlot > 2 ? pony.armor.modelArmorChestplate : pony.armor.modelArmor; ModelPony modelbase = isLegs ? pony.armor.modelArmorChestplate : pony.armor.modelArmor;
modelbase.setModelAttributes(this.renderer.getMainModel()); modelbase.setModelAttributes(this.renderer.getMainModel());
modelbase.setLivingAnimations(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks); modelbase.setLivingAnimations(entitylivingbaseIn, p_177141_2_, p_177141_3_, partialTicks);
modelbase = getArmorModel(entitylivingbaseIn, itemstack, armorSlot, modelbase);
prepareToRender((pm_newPonyArmor) modelbase, armorSlot); prepareToRender((pm_newPonyArmor) modelbase, armorSlot);
this.bindPonyArmorTexture(itemarmor, armorSlot, null); // this.bindPonyArmorTexture(itemarmor, armorSlot, null);
this.renderer.bindTexture(getArmorTexture(entitylivingbaseIn, itemstack, isLegs ? 2 : 1, null));
if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) { if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) {
int j = itemarmor.getColor(itemstack); int j = itemarmor.getColor(itemstack);
float f7 = (j >> 16 & 255) / 255.0F; float f7 = (j >> 16 & 255) / 255.0F;
@ -81,8 +79,7 @@ public class LayerPonyArmor implements LayerRenderer {
GlStateManager.color(f7, f8, f9, 1); GlStateManager.color(f7, f8, f9, 1);
modelbase.render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_, modelbase.render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_,
scale); scale);
this.renderer.bindTexture(getArmorTexture(entitylivingbaseIn, itemstack, isLegs ? 2 : 1, "overlay"));
bindPonyArmorTexture(itemarmor, armorSlot, "overlay");
} }
GlStateManager.color(1, 1, 1, 1); GlStateManager.color(1, 1, 1, 1);
modelbase.render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_, modelbase.render(entitylivingbaseIn, p_177141_2_, p_177141_3_, p_177141_5_, p_177141_6_, p_177141_7_,
@ -95,6 +92,29 @@ public class LayerPonyArmor implements LayerRenderer {
} }
} }
private ResourceLocation getArmorTexture(EntityLivingBase entity, ItemStack itemstack, int slot, String type) {
ItemArmor item = (ItemArmor) itemstack.getItem();
String texture = item.getArmorMaterial().getName();
String domain = "minecraft";
int idx = texture.indexOf(':');
if (idx != -1) {
domain = texture.substring(0, idx);
texture = texture.substring(idx + 1);
}
String s1 = String.format("%s:textures/models/armor/%s_layer_%d%s.png", domain, texture, (slot == 2 ? 2 : 1),
type == null ? "" : String.format("_%s", type));
s1 = getArmorTexture(entity, itemstack, s1, slot, type);
ResourceLocation human = getHumanResource(s1);
ResourceLocation pony = getPonyResource(human);
try {
Minecraft.getMinecraft().getResourceManager().getResource(pony);
return pony;
} catch (IOException e) {
return human;
}
}
private void prepareToRender(pm_newPonyArmor model, int slot) { private void prepareToRender(pm_newPonyArmor model, int slot) {
model.setInvisible(false); model.setInvisible(false);
@ -177,107 +197,47 @@ public class LayerPonyArmor implements LayerRenderer {
return false; return false;
} }
protected boolean bindPonyArmorTexture(ItemArmor armorPiece, int slot, String overlay) { private static ResourceLocation getHumanResource(String s1) {
String overlayText = ""; ResourceLocation human = HUMAN_ARMORS.get(s1);
if (overlay != null) { if (human == null) {
overlayText = String.format("_%s", overlay); human = new ResourceLocation(s1);
HUMAN_ARMORS.put(s1, human);
}
return human;
} }
String path = this.pony.armor.path private static ResourceLocation getPonyResource(ResourceLocation human) {
+ bipedArmorFilenamePrefix[armorPiece.getArmorMaterial().ordinal()] ResourceLocation pony = PONY_ARMORS.get(human);
+ "_layer_" + this.pony.armor.subimage(slot) + overlayText + ".png"; if (pony == null) {
if (PonyManager.getInstance().getPonyArmor() == 1 && this.pony.model instanceof pm_newPonyAdv) { String domain = human.getResourceDomain();
Object[] armorResourceAndState = this.getPonyResourceLocation(path); String path = human.getResourcePath();
renderer.bindTexture((ResourceLocation) armorResourceAndState[0]); if (domain.equals("minecraft")) {
return ((Boolean) armorResourceAndState[1]).booleanValue(); // it's a vanilla armor. I provide these.
domain = "minelittlepony";
} }
return false; path = path.replace(".png", "_pony.png");
pony = new ResourceLocation(domain, path);
PONY_ARMORS.put(human, pony);
}
return pony;
} }
protected boolean bindForgeArmorTexture(Entity playerEntity, ItemStack armorStack, ItemArmor armorPiece, int slot, private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, int slot, String type) {
String overlay) { IPonyArmor armor = MineLittlePony.getProxy().getPonyArmors();
String path = ""; if (armor != null) {
return armor.getArmorTexture(entity, item, def, slot, type);
try { }
path = String.format("textures/models/armor/%s_layer_%d%s.png", return def;
bipedArmorFilenamePrefix[armorPiece.renderIndex],
Integer.valueOf(slot == 2 ? 2 : 1),
overlay == null ? "" : String.format("_%s", overlay));
} catch (ArrayIndexOutOfBoundsException var10) {}
path = (String) MineLPReflection.forgeAPI.invokeMethod("ForgeHooksClient.getArmorTexture", (Object) null,
playerEntity, armorStack, path, Integer.valueOf(slot), overlay);
boolean ponyArmor;
if (ponyArmors.contains(path)) {
ponyArmor = this.bindPonyArmorTexture(armorPiece, slot, overlay);
} else {
ponyArmor = false;
ResourceLocation forgeResourceLocation;
if (PonyManager.getInstance().getPonyArmor() == 1 && this.pony.model instanceof pm_newPonyAdv) {
Object[] armorResourceAndState = this.getPonyResourceLocation(path);
forgeResourceLocation = (ResourceLocation) armorResourceAndState[0];
ponyArmor = ((Boolean) armorResourceAndState[1]).booleanValue();
} else {
forgeResourceLocation = field_110859_k.get(path);
if (forgeResourceLocation == null) {
forgeResourceLocation = new ResourceLocation(path);
field_110859_k.put(path, forgeResourceLocation);
} }
ponyArmor = false; private static ModelPony getArmorModel(EntityLivingBase entity, ItemStack itemstack, int slot, ModelPony def) {
} IPonyArmor armor = MineLittlePony.getProxy().getPonyArmors();
if (armor != null) {
renderer.bindTexture(forgeResourceLocation); ModelBase model = armor.getArmorModel(entity, itemstack, slot, def);
} if (model instanceof pm_newPonyArmor) {
return (ModelPony) model;
return ponyArmor;
}
protected Object[] getPonyResourceLocation(String path) {
boolean ponyArmor = false;
String ponyPath = path.replace(".png", "_pony.png");
ResourceLocation ponyResourceLocation = ponyArmorMap.get(path);
if (ponyResourceLocation == null) {
ResourceLocation ponyArmorResource = new ResourceLocation(ponyPath);
try {
TextureUtil.readImageData(Minecraft.getMinecraft().getResourceManager(), ponyArmorResource);
ponyResourceLocation = ponyArmorResource;
ponyArmorMap.put(path, ponyArmorResource);
onlyPonyArmorMap.put(path, ponyArmorResource);
ponyArmor = true;
} catch (IOException var7) {
ponyResourceLocation = field_110859_k.get(path);
if (ponyResourceLocation == null) {
ponyResourceLocation = new ResourceLocation(path);
field_110859_k.put(path, ponyResourceLocation);
}
ponyArmorMap.put(path, ponyResourceLocation);
ponyArmor = false;
}
} else {
ponyArmor = true;
ponyResourceLocation = onlyPonyArmorMap.get(path);
if (ponyResourceLocation == null) {
ponyResourceLocation = ponyArmorMap.get(path);
ponyArmor = false;
} }
} }
return def;
return new Object[] { ponyResourceLocation, Boolean.valueOf(ponyArmor) };
}
static {
MineLPReflection.preCall();
for (int i = 1; i <= 2; ++i) {
for (String prefix : bipedArmorFilenamePrefix) {
ponyArmors.add("textures/models/armor/" + prefix + "_layer_" + i + ".png");
}
}
ponyArmors.add("textures/models/armor/leather_layer_1_overlay.png");
ponyArmors.add("textures/models/armor/leather_layer_2_overlay.png");
} }
} }