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 for (int var3 = 0; var3 < this.blocksEffectiveAgainst.length; ++var3) 038 { 039 if (this.blocksEffectiveAgainst[var3] == par2Block) 040 { 041 return this.efficiencyOnProperMaterial; 042 } 043 } 044 045 return 1.0F; 046 } 047 048 /** 049 * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise 050 * the damage on the stack. 051 */ 052 public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving) 053 { 054 par1ItemStack.damageItem(2, par3EntityLiving); 055 return true; 056 } 057 058 public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving) 059 { 060 if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D) 061 { 062 par1ItemStack.damageItem(1, par7EntityLiving); 063 } 064 065 return true; 066 } 067 068 /** 069 * Returns the damage against a given entity. 070 */ 071 public int getDamageVsEntity(Entity par1Entity) 072 { 073 return this.damageVsEntity; 074 } 075 076 @SideOnly(Side.CLIENT) 077 078 /** 079 * Returns True is the item is renderer in full 3D when hold. 080 */ 081 public boolean isFull3D() 082 { 083 return true; 084 } 085 086 /** 087 * Return the enchantability factor of the item, most of the time is based on material. 088 */ 089 public int getItemEnchantability() 090 { 091 return this.toolMaterial.getEnchantability(); 092 } 093 094 /** 095 * Return the name for this tool's material. 096 */ 097 public String getToolMaterialName() 098 { 099 return this.toolMaterial.toString(); 100 } 101 102 /** 103 * Return whether this item is repairable in an anvil. 104 */ 105 public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) 106 { 107 return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); 108 } 109 110 /** FORGE: Overridden to allow custom tool effectiveness */ 111 @Override 112 public float getStrVsBlock(ItemStack stack, Block block, int meta) 113 { 114 if (ForgeHooks.isToolEffective(stack, block, meta)) 115 { 116 return efficiencyOnProperMaterial; 117 } 118 return getStrVsBlock(stack, block); 119 } 120 }