    001    package net.minecraft.item;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import net.minecraft.block.Block;
    006    import net.minecraft.creativetab.CreativeTabs;
    007    import net.minecraft.entity.Entity;
    008    import net.minecraft.entity.EntityLiving;
    009    import net.minecraft.world.World;
    010    import net.minecraftforge.common.ForgeHooks;
    011
    012    public class ItemTool extends Item
    013    {
    014        /** Array of blocks the tool has extra effect against. */
    015        private Block[] blocksEffectiveAgainst;
    016        public float efficiencyOnProperMaterial = 4.0F;
    017
    018        /** Damage versus entities. */
    019        public int damageVsEntity;
    020
    021        /** The material this tool is made from. */
    022        protected EnumToolMaterial toolMaterial;
    023
    024        protected ItemTool(int par1, int par2, EnumToolMaterial par3EnumToolMaterial, Block[] par4ArrayOfBlock)
    025        {
    026            super(par1);
    027            this.toolMaterial = par3EnumToolMaterial;
    028            this.blocksEffectiveAgainst = par4ArrayOfBlock;
    029            this.maxStackSize = 1;
    030            this.setMaxDamage(par3EnumToolMaterial.getMaxUses());
    031            this.efficiencyOnProperMaterial = par3EnumToolMaterial.getEfficiencyOnProperMaterial();
    032            this.damageVsEntity = par2 + par3EnumToolMaterial.getDamageVsEntity();
    033            this.setCreativeTab(CreativeTabs.tabTools);
    034        }
    035
    036        /**
    037         * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
    038         * sword
    039         */
    040        public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
    041        {
    042            for (int var3 = 0; var3 < this.blocksEffectiveAgainst.length; ++var3)
    043            {
    044                if (this.blocksEffectiveAgainst[var3] == 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        /**
    100         * Return the name for this tool's material.
    101         */
    102        public String getToolMaterialName()
    103        {
    104            return this.toolMaterial.toString();
    105        }
    106
    107        /**
    108         * Return whether this item is repairable in an anvil.
    109         */
    110        public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
    111        {
    112            return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
    113        }
    114
    115        /** FORGE: Overridden to allow custom tool effectiveness */
    116        @Override
    117        public float getStrVsBlock(ItemStack stack, Block block, int meta)
    118        {
    119            if (ForgeHooks.isToolEffective(stack, block, meta))
    120            {
    121                return efficiencyOnProperMaterial;
    122            }
    123            return getStrVsBlock(stack, block);
    124        }
    125    }