001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005
006 public class ItemArmor extends Item
007 {
008 /** Holds the 'base' maxDamage that each armorType have. */
009 private static final int[] maxDamageArray = new int[] {11, 16, 15, 13};
010
011 /**
012 * Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots
013 */
014 public final int armorType;
015
016 /** Holds the amount of damage that the armor reduces at full durability. */
017 public final int damageReduceAmount;
018
019 /**
020 * Used on RenderPlayer to select the correspondent armor to be rendered on the player: 0 is cloth, 1 is chain, 2 is
021 * iron, 3 is diamond and 4 is gold.
022 */
023 public final int renderIndex;
024
025 /** The EnumArmorMaterial used for this ItemArmor */
026 private final EnumArmorMaterial material;
027
028 public ItemArmor(int par1, EnumArmorMaterial par2EnumArmorMaterial, int par3, int par4)
029 {
030 super(par1);
031 this.material = par2EnumArmorMaterial;
032 this.armorType = par4;
033 this.renderIndex = par3;
034 this.damageReduceAmount = par2EnumArmorMaterial.getDamageReductionAmount(par4);
035 this.setMaxDamage(par2EnumArmorMaterial.getDurability(par4));
036 this.maxStackSize = 1;
037 this.setCreativeTab(CreativeTabs.tabCombat);
038 }
039
040 @SideOnly(Side.CLIENT)
041 public int func_82790_a(ItemStack par1ItemStack, int par2)
042 {
043 if (par2 > 0)
044 {
045 return 16777215;
046 }
047 else
048 {
049 int var3 = this.func_82814_b(par1ItemStack);
050
051 if (var3 < 0)
052 {
053 var3 = 16777215;
054 }
055
056 return var3;
057 }
058 }
059
060 @SideOnly(Side.CLIENT)
061 public boolean requiresMultipleRenderPasses()
062 {
063 return this.material == EnumArmorMaterial.CLOTH;
064 }
065
066 /**
067 * Return the enchantability factor of the item, most of the time is based on material.
068 */
069 public int getItemEnchantability()
070 {
071 return this.material.getEnchantability();
072 }
073
074 public EnumArmorMaterial func_82812_d()
075 {
076 return this.material;
077 }
078
079 public boolean func_82816_b_(ItemStack par1ItemStack)
080 {
081 return this.material != EnumArmorMaterial.CLOTH ? false : (!par1ItemStack.hasTagCompound() ? false : (!par1ItemStack.getTagCompound().hasKey("display") ? false : par1ItemStack.getTagCompound().getCompoundTag("display").hasKey("color")));
082 }
083
084 public int func_82814_b(ItemStack par1ItemStack)
085 {
086 if (this.material != EnumArmorMaterial.CLOTH)
087 {
088 return -1;
089 }
090 else
091 {
092 NBTTagCompound var2 = par1ItemStack.getTagCompound();
093
094 if (var2 == null)
095 {
096 return 10511680;
097 }
098 else
099 {
100 NBTTagCompound var3 = var2.getCompoundTag("display");
101 return var3 == null ? 10511680 : (var3.hasKey("color") ? var3.getInteger("color") : 10511680);
102 }
103 }
104 }
105
106 @SideOnly(Side.CLIENT)
107
108 /**
109 * Gets an icon index based on an item's damage value and the given render pass
110 */
111 public int getIconFromDamageForRenderPass(int par1, int par2)
112 {
113 return par2 == 1 ? this.iconIndex + 144 : super.getIconFromDamageForRenderPass(par1, par2);
114 }
115
116 public void func_82815_c(ItemStack par1ItemStack)
117 {
118 if (this.material == EnumArmorMaterial.CLOTH)
119 {
120 NBTTagCompound var2 = par1ItemStack.getTagCompound();
121
122 if (var2 != null)
123 {
124 NBTTagCompound var3 = var2.getCompoundTag("display");
125
126 if (var3.hasKey("color"))
127 {
128 var3.func_82580_o("color");
129 }
130 }
131 }
132 }
133
134 public void func_82813_b(ItemStack par1ItemStack, int par2)
135 {
136 if (this.material != EnumArmorMaterial.CLOTH)
137 {
138 throw new UnsupportedOperationException("Can\'t dye non-leather!");
139 }
140 else
141 {
142 NBTTagCompound var3 = par1ItemStack.getTagCompound();
143
144 if (var3 == null)
145 {
146 var3 = new NBTTagCompound();
147 par1ItemStack.setTagCompound(var3);
148 }
149
150 NBTTagCompound var4 = var3.getCompoundTag("display");
151
152 if (!var3.hasKey("display"))
153 {
154 var3.setCompoundTag("display", var4);
155 }
156
157 var4.setInteger("color", par2);
158 }
159 }
160
161 public boolean func_82789_a(ItemStack par1ItemStack, ItemStack par2ItemStack)
162 {
163 return this.material.func_82845_b() == par2ItemStack.itemID ? true : super.func_82789_a(par1ItemStack, par2ItemStack);
164 }
165
166 /**
167 * Returns the 'max damage' factor array for the armor, each piece of armor have a durability factor (that gets
168 * multiplied by armor material factor)
169 */
170 static int[] getMaxDamageArray()
171 {
172 return maxDamageArray;
173 }
174 }