001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.util.List; 006 007 import net.minecraftforge.common.ForgeHooks; 008 import net.minecraftforge.common.MinecraftForge; 009 import net.minecraftforge.event.entity.player.BonemealEvent; 010 011 public class ItemDye extends Item 012 { 013 /** List of dye color names */ 014 public static final String[] dyeColorNames = new String[] {"black", "red", "green", "brown", "blue", "purple", "cyan", "silver", "gray", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white"}; 015 public static final int[] dyeColors = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 2651799, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320}; 016 017 public ItemDye(int par1) 018 { 019 super(par1); 020 this.setHasSubtypes(true); 021 this.setMaxDamage(0); 022 this.setCreativeTab(CreativeTabs.tabMaterials); 023 } 024 025 @SideOnly(Side.CLIENT) 026 027 /** 028 * Gets an icon index based on an item's damage value 029 */ 030 public int getIconFromDamage(int par1) 031 { 032 int var2 = MathHelper.clamp_int(par1, 0, 15); 033 return this.iconIndex + var2 % 8 * 16 + var2 / 8; 034 } 035 036 public String getItemNameIS(ItemStack par1ItemStack) 037 { 038 int var2 = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15); 039 return super.getItemName() + "." + dyeColorNames[var2]; 040 } 041 042 /** 043 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return 044 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS 045 */ 046 public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) 047 { 048 if (!par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack)) 049 { 050 return false; 051 } 052 else 053 { 054 int var11; 055 int var12; 056 057 if (par1ItemStack.getItemDamage() == 15) 058 { 059 var11 = par3World.getBlockId(par4, par5, par6); 060 061 BonemealEvent event = new BonemealEvent(par2EntityPlayer, par3World, var11, par4, par5, par6); 062 if (MinecraftForge.EVENT_BUS.post(event)) 063 { 064 return false; 065 } 066 067 if (event.isHandeled()) 068 { 069 if (!par3World.isRemote) 070 { 071 par1ItemStack.stackSize--; 072 } 073 return true; 074 } 075 076 if (var11 == Block.sapling.blockID) 077 { 078 if (!par3World.isRemote) 079 { 080 ((BlockSapling)Block.sapling).growTree(par3World, par4, par5, par6, par3World.rand); 081 --par1ItemStack.stackSize; 082 } 083 084 return true; 085 } 086 087 if (var11 == Block.mushroomBrown.blockID || var11 == Block.mushroomRed.blockID) 088 { 089 if (!par3World.isRemote && ((BlockMushroom)Block.blocksList[var11]).fertilizeMushroom(par3World, par4, par5, par6, par3World.rand)) 090 { 091 --par1ItemStack.stackSize; 092 } 093 094 return true; 095 } 096 097 if (var11 == Block.melonStem.blockID || var11 == Block.pumpkinStem.blockID) 098 { 099 if (par3World.getBlockMetadata(par4, par5, par6) == 7) 100 { 101 return false; 102 } 103 104 if (!par3World.isRemote) 105 { 106 ((BlockStem)Block.blocksList[var11]).fertilizeStem(par3World, par4, par5, par6); 107 --par1ItemStack.stackSize; 108 } 109 110 return true; 111 } 112 113 if (var11 > 0 && Block.blocksList[var11] instanceof BlockCrops) 114 { 115 if (par3World.getBlockMetadata(par4, par5, par6) == 7) 116 { 117 return false; 118 } 119 120 if (!par3World.isRemote) 121 { 122 ((BlockCrops)Block.blocksList[var11]).fertilize(par3World, par4, par5, par6); 123 --par1ItemStack.stackSize; 124 } 125 126 return true; 127 } 128 129 if (var11 == Block.cocoaPlant.blockID) 130 { 131 if (!par3World.isRemote) 132 { 133 par3World.setBlockMetadataWithNotify(par4, par5, par6, 8 | BlockDirectional.getDirection(par3World.getBlockMetadata(par4, par5, par6))); 134 --par1ItemStack.stackSize; 135 } 136 137 return true; 138 } 139 140 if (var11 == Block.grass.blockID) 141 { 142 if (!par3World.isRemote) 143 { 144 --par1ItemStack.stackSize; 145 label137: 146 147 for (var12 = 0; var12 < 128; ++var12) 148 { 149 int var13 = par4; 150 int var14 = par5 + 1; 151 int var15 = par6; 152 153 for (int var16 = 0; var16 < var12 / 16; ++var16) 154 { 155 var13 += itemRand.nextInt(3) - 1; 156 var14 += (itemRand.nextInt(3) - 1) * itemRand.nextInt(3) / 2; 157 var15 += itemRand.nextInt(3) - 1; 158 159 if (par3World.getBlockId(var13, var14 - 1, var15) != Block.grass.blockID || par3World.isBlockNormalCube(var13, var14, var15)) 160 { 161 continue label137; 162 } 163 } 164 165 if (par3World.getBlockId(var13, var14, var15) == 0) 166 { 167 if (itemRand.nextInt(10) != 0) 168 { 169 if (Block.tallGrass.canBlockStay(par3World, var13, var14, var15)) 170 { 171 par3World.setBlockAndMetadataWithNotify(var13, var14, var15, Block.tallGrass.blockID, 1); 172 } 173 } 174 else 175 { 176 ForgeHooks.plantGrass(par3World, var13, var14, var15); 177 } 178 } 179 } 180 } 181 182 return true; 183 } 184 } 185 else if (par1ItemStack.getItemDamage() == 3) 186 { 187 var11 = par3World.getBlockId(par4, par5, par6); 188 var12 = par3World.getBlockMetadata(par4, par5, par6); 189 190 if (var11 == Block.wood.blockID && BlockLog.limitToValidMetadata(var12) == 3) 191 { 192 if (par7 == 0) 193 { 194 return false; 195 } 196 197 if (par7 == 1) 198 { 199 return false; 200 } 201 202 if (par7 == 2) 203 { 204 --par6; 205 } 206 207 if (par7 == 3) 208 { 209 ++par6; 210 } 211 212 if (par7 == 4) 213 { 214 --par4; 215 } 216 217 if (par7 == 5) 218 { 219 ++par4; 220 } 221 222 if (par3World.isAirBlock(par4, par5, par6)) 223 { 224 par3World.setBlockWithNotify(par4, par5, par6, Block.cocoaPlant.blockID); 225 226 if (par3World.getBlockId(par4, par5, par6) == Block.cocoaPlant.blockID) 227 { 228 Block.blocksList[Block.cocoaPlant.blockID].updateBlockMetadata(par3World, par4, par5, par6, par7, par8, par9, par10); 229 } 230 231 if (!par2EntityPlayer.capabilities.isCreativeMode) 232 { 233 --par1ItemStack.stackSize; 234 } 235 } 236 237 return true; 238 } 239 } 240 241 return false; 242 } 243 } 244 245 /** 246 * dye sheep, place saddles, etc ... 247 */ 248 public boolean itemInteractionForEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving) 249 { 250 if (par2EntityLiving instanceof EntitySheep) 251 { 252 EntitySheep var3 = (EntitySheep)par2EntityLiving; 253 int var4 = BlockCloth.getBlockFromDye(par1ItemStack.getItemDamage()); 254 255 if (!var3.getSheared() && var3.getFleeceColor() != var4) 256 { 257 var3.setFleeceColor(var4); 258 --par1ItemStack.stackSize; 259 } 260 261 return true; 262 } 263 else 264 { 265 return false; 266 } 267 } 268 269 @SideOnly(Side.CLIENT) 270 271 /** 272 * returns a list of items with the same ID, but different meta (eg: dye returns 16 items) 273 */ 274 public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) 275 { 276 for (int var4 = 0; var4 < 16; ++var4) 277 { 278 par3List.add(new ItemStack(par1, 1, var4)); 279 } 280 } 281 }