From 6b0d1bb3198070f68aabcb21346ff8d915f64d96 Mon Sep 17 00:00:00 2001 From: LexManos Date: Thu, 4 Apr 2013 17:28:50 -0700 Subject: [PATCH] Deprecate IArmorTextureProvider, moved to Item. And exposed more information to the function. Closes #365 --- .../client/ForgeHooksClient.java | 10 +++--- .../common/IArmorTextureProvider.java | 1 + .../renderer/entity/RenderBiped.java.patch | 31 ++++++++++++++++--- .../renderer/entity/RenderPlayer.java.patch | 26 ++++++++++++---- .../net/minecraft/item/Item.java.patch | 27 +++++++++++++--- 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/client/net/minecraftforge/client/ForgeHooksClient.java b/client/net/minecraftforge/client/ForgeHooksClient.java index 0aa4640d02..9b5cc019ff 100644 --- a/client/net/minecraftforge/client/ForgeHooksClient.java +++ b/client/net/minecraftforge/client/ForgeHooksClient.java @@ -12,6 +12,7 @@ import cpw.mods.fml.client.FMLClientHandler; import net.minecraft.client.Minecraft; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.client.texturepacks.ITexturePack; @@ -42,13 +43,10 @@ public class ForgeHooksClient return FMLClientHandler.instance().getClient().renderEngine; } - public static String getArmorTexture(ItemStack armor, String _default) + public static String getArmorTexture(Entity entity, ItemStack armor, String _default, int slot, int layer) { - if (armor.getItem() instanceof IArmorTextureProvider) - { - return ((IArmorTextureProvider)armor.getItem()).getArmorTextureFile(armor); - } - return _default; + String result = armor.getItem().getArmorTexture(armor, entity, slot, layer); + return result != null ? result : _default; } public static boolean renderEntityItem(EntityItem entity, ItemStack item, float bobing, float rotation, Random random, RenderEngine engine, RenderBlocks renderBlocks) diff --git a/common/net/minecraftforge/common/IArmorTextureProvider.java b/common/net/minecraftforge/common/IArmorTextureProvider.java index 294c678e14..4106d170e7 100644 --- a/common/net/minecraftforge/common/IArmorTextureProvider.java +++ b/common/net/minecraftforge/common/IArmorTextureProvider.java @@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack; * It allows for the application of a custom texture file to the player skin * when the armor is worn. */ +@Deprecated //See Item.getArmorTexture public interface IArmorTextureProvider { diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderBiped.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderBiped.java.patch index c35035a6d5..baba3e6727 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderBiped.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderBiped.java.patch @@ -21,11 +21,34 @@ { ItemArmor itemarmor = (ItemArmor)item; - this.loadTexture("/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png"); -+ this.loadTexture(ForgeHooksClient.getArmorTexture(itemstack, "/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png")); ++ this.loadTexture(ForgeHooksClient.getArmorTexture(par1EntityLiving, itemstack, "/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png", par2, 1)); ModelBiped modelbiped = par2 == 2 ? this.field_82425_h : this.field_82423_g; modelbiped.bipedHead.showModel = par2 == 0; modelbiped.bipedHeadwear.showModel = par2 == 0; -@@ -174,9 +180,12 @@ +@@ -87,9 +93,10 @@ + + float f1 = 1.0F; + +- if (itemarmor.getArmorMaterial() == EnumArmorMaterial.CLOTH) +- { +- int j = itemarmor.getColor(itemstack); ++ //Move out of if to allow for more then just CLOTH to have color ++ int j = itemarmor.getColor(itemstack); ++ if (j != -1) ++ { + float f2 = (float)(j >> 16 & 255) / 255.0F; + float f3 = (float)(j >> 8 & 255) / 255.0F; + float f4 = (float)(j & 255) / 255.0F; +@@ -128,7 +135,7 @@ + if (item instanceof ItemArmor) + { + ItemArmor itemarmor = (ItemArmor)item; +- this.loadTexture("/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png"); ++ this.loadTexture(ForgeHooksClient.getArmorTexture(par1EntityLiving, itemstack, "/armor/" + bipedArmorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png", par2, 2)); + float f1 = 1.0F; + GL11.glColor3f(f1, f1, f1); + } +@@ -174,9 +181,12 @@ GL11.glPushMatrix(); this.modelBipedMain.bipedHead.postRender(0.0625F); @@ -41,7 +64,7 @@ { f2 = 0.625F; GL11.glTranslatef(0.0F, -0.25F, 0.0F); -@@ -218,7 +227,10 @@ +@@ -218,7 +228,10 @@ this.modelBipedMain.bipedRightArm.postRender(0.0625F); GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F); @@ -53,7 +76,7 @@ { f2 = 0.5F; GL11.glTranslatef(0.0F, 0.1875F, -0.3125F); -@@ -265,7 +277,10 @@ +@@ -265,7 +278,10 @@ if (itemstack.getItem().requiresMultipleRenderPasses()) { diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch index dc8c2d6127..0bc878381c 100644 --- a/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/entity/RenderPlayer.java.patch @@ -28,20 +28,34 @@ { ItemArmor itemarmor = (ItemArmor)item; - this.loadTexture("/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png"); -+ this.loadTexture(ForgeHooksClient.getArmorTexture(itemstack, "/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png")); ++ this.loadTexture(ForgeHooksClient.getArmorTexture(par1EntityPlayer, itemstack, "/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + ".png", par2, 1)); ModelBiped modelbiped = par2 == 2 ? this.modelArmor : this.modelArmorChestplate; modelbiped.bipedHead.showModel = par2 == 0; modelbiped.bipedHeadwear.showModel = par2 == 0; -@@ -125,7 +133,7 @@ +@@ -84,9 +92,10 @@ + + float f1 = 1.0F; + +- if (itemarmor.getArmorMaterial() == EnumArmorMaterial.CLOTH) +- { +- int j = itemarmor.getColor(itemstack); ++ //Move outside if to allow for more then just CLOTH ++ int j = itemarmor.getColor(itemstack); ++ if (j != -1) ++ { + float f2 = (float)(j >> 16 & 255) / 255.0F; + float f3 = (float)(j >> 8 & 255) / 255.0F; + float f4 = (float)(j & 255) / 255.0F; +@@ -125,7 +134,7 @@ if (item instanceof ItemArmor) { ItemArmor itemarmor = (ItemArmor)item; - this.loadTexture("/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png"); -+ this.loadTexture(ForgeHooksClient.getArmorTexture(itemstack, "/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png")); ++ this.loadTexture(ForgeHooksClient.getArmorTexture(par1EntityPlayer, itemstack, "/armor/" + armorFilenamePrefix[itemarmor.renderIndex] + "_" + (par2 == 2 ? 2 : 1) + "_b.png", par2, 2)); float f1 = 1.0F; GL11.glColor3f(f1, f1, f1); } -@@ -184,9 +192,12 @@ +@@ -184,9 +193,12 @@ this.modelBipedMain.bipedHead.postRender(0.0625F); float f2; @@ -57,7 +71,7 @@ { f2 = 0.625F; GL11.glTranslatef(0.0F, -0.25F, 0.0F); -@@ -304,7 +315,10 @@ +@@ -304,7 +316,10 @@ enumaction = itemstack1.getItemUseAction(); } @@ -69,7 +83,7 @@ { f3 = 0.5F; GL11.glTranslatef(0.0F, 0.1875F, -0.3125F); -@@ -361,7 +375,7 @@ +@@ -361,7 +376,7 @@ if (itemstack1.getItem().requiresMultipleRenderPasses()) { diff --git a/patches/minecraft/net/minecraft/item/Item.java.patch b/patches/minecraft/net/minecraft/item/Item.java.patch index 57b2f75831..0bb47bafdd 100644 --- a/patches/minecraft/net/minecraft/item/Item.java.patch +++ b/patches/minecraft/net/minecraft/item/Item.java.patch @@ -8,17 +8,18 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionHelper; import net.minecraft.stats.StatList; -@@ -23,7 +24,9 @@ +@@ -23,7 +24,10 @@ import net.minecraft.util.StatCollector; import net.minecraft.util.StringTranslate; import net.minecraft.util.Vec3; +import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; +import net.minecraftforge.common.ChestGenHooks; ++import net.minecraftforge.common.IArmorTextureProvider; public class Item { -@@ -238,13 +241,16 @@ +@@ -238,13 +242,16 @@ /** Icon index in the icons table. */ protected Icon iconIndex; @@ -36,7 +37,7 @@ } itemsList[256 + par1] = this; -@@ -640,6 +646,10 @@ +@@ -640,6 +647,10 @@ float f7 = f4 * f5; float f8 = f3 * f5; double d3 = 5.0D; @@ -47,7 +48,7 @@ Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3); return par1World.rayTraceBlocks_do_do(vec3, vec31, par3, !par3); } -@@ -720,4 +730,349 @@ +@@ -720,4 +731,367 @@ { StatList.initStats(); } @@ -396,4 +397,22 @@ + return getDamageVsEntity(par1Entity); + } + ++ @Deprecated private final boolean isArmorProvider = this instanceof IArmorTextureProvider; ++ /** ++ * Called by RenderBiped and RenderPlayer to determine the armor texture that ++ * should be use for the currently equiped item. ++ * This will only be called on instances of ItemArmor. ++ * ++ * Returning null from this function will use the default value. ++ * ++ * @param stack ItemStack for the equpt armor ++ * @param entity The entity wearing the armor ++ * @param slot The slot the armor is in ++ * @param layer The render layer, either 1 or 2, 2 is only used for CLOTH armor by default ++ * @return Path of texture to bind, or null to use default ++ */ ++ public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer) ++ { ++ return isArmorProvider ? ((IArmorTextureProvider)this).getArmorTextureFile(stack) : null; ++ } }