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 getColorFromItemStack(ItemStack par1ItemStack, int par2)
025        {
026            return this.blockRef.getRenderColor(par1ItemStack.getItemDamage());
027        }
028    
029        /**
030         * Returns the metadata of the block which this Item (ItemBlock) can place
031         */
032        public int getMetadata(int par1)
033        {
034            return par1;
035        }
036    
037        /**
038         * Sets the array of strings to be used for name lookups from item damage to metadata
039         */
040        public ItemColored setBlockNames(String[] par1ArrayOfStr)
041        {
042            this.blockNames = par1ArrayOfStr;
043            return this;
044        }
045    
046        @SideOnly(Side.CLIENT)
047    
048        /**
049         * Gets an icon index based on an item's damage value
050         */
051        public int getIconFromDamage(int par1)
052        {
053            return this.blockRef.getBlockTextureFromSideAndMetadata(0, par1);
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    }