    001    package net.minecraft.item;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.block.Block;
    006
    007    public class ItemColored extends ItemBlock
    008    {
    009        private final Block blockRef;
    010        private String[] blockNames;
    011
    012        public ItemColored(int par1, boolean par2)
    013        {
    014            super(par1);
    015            this.blockRef = Block.blocksList[this.getBlockID()];
    016
    017            if (par2)
    018            {
    019                this.setMaxDamage(0);
    020                this.setHasSubtypes(true);
    021            }
    022        }
    023
    024        @SideOnly(Side.CLIENT)
    025        public int getColorFromItemStack(ItemStack par1ItemStack, int par2)
    026        {
    027            return this.blockRef.getRenderColor(par1ItemStack.getItemDamage());
    028        }
    029
    030        /**
    031         * Returns the metadata of the block which this Item (ItemBlock) can place
    032         */
    033        public int getMetadata(int par1)
    034        {
    035            return par1;
    036        }
    037
    038        /**
    039         * Sets the array of strings to be used for name lookups from item damage to metadata
    040         */
    041        public ItemColored setBlockNames(String[] par1ArrayOfStr)
    042        {
    043            this.blockNames = par1ArrayOfStr;
    044            return this;
    045        }
    046
    047        @SideOnly(Side.CLIENT)
    048
    049        /**
    050         * Gets an icon index based on an item's damage value
    051         */
    052        public int getIconFromDamage(int par1)
    053        {
    054            return this.blockRef.getBlockTextureFromSideAndMetadata(0, par1);
    055        }
    056
    057        public String getItemNameIS(ItemStack par1ItemStack)
    058        {
    059            if (this.blockNames == null)
    060            {
    061                return super.getItemNameIS(par1ItemStack);
    062            }
    063            else
    064            {
    065                int var2 = par1ItemStack.getItemDamage();
    066                return var2 >= 0 && var2 < this.blockNames.length ? super.getItemNameIS(par1ItemStack) + "." + this.blockNames[var2] : super.getItemNameIS(par1ItemStack);
    067            }
    068        }
    069    }