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