001 package net.minecraft.src;
002
003 import net.minecraftforge.common.ForgeHooks;
004 import cpw.mods.fml.common.Side;
005 import cpw.mods.fml.common.asm.SideOnly;
006
007 public class ItemTool extends Item
008 {
009 /** Array of blocks the tool has extra effect against. */
010 private Block[] blocksEffectiveAgainst;
011 public float efficiencyOnProperMaterial = 4.0F;
012
013 /** Damage versus entities. */
014 public int damageVsEntity;
015
016 /** The material this tool is made from. */
017 protected EnumToolMaterial toolMaterial;
018
019 protected ItemTool(int par1, int par2, EnumToolMaterial par3EnumToolMaterial, Block[] par4ArrayOfBlock)
020 {
021 super(par1);
022 this.toolMaterial = par3EnumToolMaterial;
023 this.blocksEffectiveAgainst = par4ArrayOfBlock;
024 this.maxStackSize = 1;
025 this.setMaxDamage(par3EnumToolMaterial.getMaxUses());
026 this.efficiencyOnProperMaterial = par3EnumToolMaterial.getEfficiencyOnProperMaterial();
027 this.damageVsEntity = par2 + par3EnumToolMaterial.getDamageVsEntity();
028 this.setCreativeTab(CreativeTabs.tabTools);
029 }
030
031 /**
032 * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
033 * sword
034 */
035 public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
036 {
037 Block[] var3 = this.blocksEffectiveAgainst;
038 int var4 = var3.length;
039
040 for (int var5 = 0; var5 < var4; ++var5)
041 {
042 Block var6 = var3[var5];
043
044 if (var6 == par2Block)
045 {
046 return this.efficiencyOnProperMaterial;
047 }
048 }
049
050 return 1.0F;
051 }
052
053 /**
054 * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
055 * the damage on the stack.
056 */
057 public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
058 {
059 par1ItemStack.damageItem(2, par3EntityLiving);
060 return true;
061 }
062
063 public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
064 {
065 if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
066 {
067 par1ItemStack.damageItem(1, par7EntityLiving);
068 }
069
070 return true;
071 }
072
073 /**
074 * Returns the damage against a given entity.
075 */
076 public int getDamageVsEntity(Entity par1Entity)
077 {
078 return this.damageVsEntity;
079 }
080
081 @SideOnly(Side.CLIENT)
082
083 /**
084 * Returns True is the item is renderer in full 3D when hold.
085 */
086 public boolean isFull3D()
087 {
088 return true;
089 }
090
091 /**
092 * Return the enchantability factor of the item, most of the time is based on material.
093 */
094 public int getItemEnchantability()
095 {
096 return this.toolMaterial.getEnchantability();
097 }
098
099 public String func_77861_e()
100 {
101 return this.toolMaterial.toString();
102 }
103
104 public boolean func_82789_a(ItemStack par1ItemStack, ItemStack par2ItemStack)
105 {
106 return this.toolMaterial.func_82844_f() == par2ItemStack.itemID ? true : super.func_82789_a(par1ItemStack, par2ItemStack);
107 }
108
109 /** FORGE: Overridden to allow custom tool effectiveness */
110 @Override
111 public float getStrVsBlock(ItemStack stack, Block block, int meta)
112 {
113 if (ForgeHooks.isToolEffective(stack, block, meta))
114 {
115 return efficiencyOnProperMaterial;
116 }
117 return getStrVsBlock(stack, block);
118 }
119 }