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