    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 getColorFromItemStack(ItemStack par1ItemStack, int par2)
    042        {
    043            if (par2 > 0)
    044            {
    045                return 16777215;
    046            }
    047            else
    048            {
    049                int var3 = this.getColor(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        /**
    075         * Return the armor material for this armor item.
    076         */
    077        public EnumArmorMaterial getArmorMaterial()
    078        {
    079            return this.material;
    080        }
    081
    082        /**
    083         * Return whether the specified armor ItemStack has a color.
    084         */
    085        public boolean hasColor(ItemStack par1ItemStack)
    086        {
    087            return this.material != EnumArmorMaterial.CLOTH ? false : (!par1ItemStack.hasTagCompound() ? false : (!par1ItemStack.getTagCompound().hasKey("display") ? false : par1ItemStack.getTagCompound().getCompoundTag("display").hasKey("color")));
    088        }
    089
    090        /**
    091         * Return the color for the specified armor ItemStack.
    092         */
    093        public int getColor(ItemStack par1ItemStack)
    094        {
    095            if (this.material != EnumArmorMaterial.CLOTH)
    096            {
    097                return -1;
    098            }
    099            else
    100            {
    101                NBTTagCompound var2 = par1ItemStack.getTagCompound();
    102
    103                if (var2 == null)
    104                {
    105                    return 10511680;
    106                }
    107                else
    108                {
    109                    NBTTagCompound var3 = var2.getCompoundTag("display");
    110                    return var3 == null ? 10511680 : (var3.hasKey("color") ? var3.getInteger("color") : 10511680);
    111                }
    112            }
    113        }
    114
    115        @SideOnly(Side.CLIENT)
    116
    117        /**
    118         * Gets an icon index based on an item's damage value and the given render pass
    119         */
    120        public int getIconFromDamageForRenderPass(int par1, int par2)
    121        {
    122            return par2 == 1 ? this.iconIndex + 144 : super.getIconFromDamageForRenderPass(par1, par2);
    123        }
    124
    125        /**
    126         * Remove the color from the specified armor ItemStack.
    127         */
    128        public void removeColor(ItemStack par1ItemStack)
    129        {
    130            if (this.material == EnumArmorMaterial.CLOTH)
    131            {
    132                NBTTagCompound var2 = par1ItemStack.getTagCompound();
    133
    134                if (var2 != null)
    135                {
    136                    NBTTagCompound var3 = var2.getCompoundTag("display");
    137
    138                    if (var3.hasKey("color"))
    139                    {
    140                        var3.removeTag("color");
    141                    }
    142                }
    143            }
    144        }
    145
    146        public void func_82813_b(ItemStack par1ItemStack, int par2)
    147        {
    148            if (this.material != EnumArmorMaterial.CLOTH)
    149            {
    150                throw new UnsupportedOperationException("Can\'t dye non-leather!");
    151            }
    152            else
    153            {
    154                NBTTagCompound var3 = par1ItemStack.getTagCompound();
    155
    156                if (var3 == null)
    157                {
    158                    var3 = new NBTTagCompound();
    159                    par1ItemStack.setTagCompound(var3);
    160                }
    161
    162                NBTTagCompound var4 = var3.getCompoundTag("display");
    163
    164                if (!var3.hasKey("display"))
    165                {
    166                    var3.setCompoundTag("display", var4);
    167                }
    168
    169                var4.setInteger("color", par2);
    170            }
    171        }
    172
    173        /**
    174         * Return whether this item is repairable in an anvil.
    175         */
    176        public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
    177        {
    178            return this.material.getArmorCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
    179        }
    180
    181        /**
    182         * Returns the 'max damage' factor array for the armor, each piece of armor have a durability factor (that gets
    183         * multiplied by armor material factor)
    184         */
    185        static int[] getMaxDamageArray()
    186        {
    187            return maxDamageArray;
    188        }
    189    }