Deprecate IArmorTextureProvider, moved to Item. And exposed more information to the function. Closes #365

This commit is contained in:
LexManos 2013-04-04 17:28:50 -07:00
parent 488322baa2
commit 6b0d1bb319
5 changed files with 75 additions and 20 deletions

View file

@ -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)

View file

@ -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
{

View file

@ -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())
{

View file

@ -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())
{

View file

@ -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;
+ }
}