001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    public class ItemSword extends Item
007    {
008        private int weaponDamage;
009        private final EnumToolMaterial toolMaterial;
010    
011        public ItemSword(int par1, EnumToolMaterial par2EnumToolMaterial)
012        {
013            super(par1);
014            this.toolMaterial = par2EnumToolMaterial;
015            this.maxStackSize = 1;
016            this.setMaxDamage(par2EnumToolMaterial.getMaxUses());
017            this.setCreativeTab(CreativeTabs.tabCombat);
018            this.weaponDamage = 4 + par2EnumToolMaterial.getDamageVsEntity();
019        }
020    
021        public int func_82803_g()
022        {
023            return this.toolMaterial.getDamageVsEntity();
024        }
025    
026        /**
027         * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if
028         * sword
029         */
030        public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
031        {
032            if (par2Block.blockID == Block.web.blockID)
033            {
034                return 15.0F;
035            }
036            else
037            {
038                Material var3 = par2Block.blockMaterial;
039                return var3 != Material.plants && var3 != Material.vine && var3 != Material.field_76261_t && var3 != Material.leaves && var3 != Material.pumpkin ? 1.0F : 1.5F;
040            }
041        }
042    
043        /**
044         * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
045         * the damage on the stack.
046         */
047        public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
048        {
049            par1ItemStack.damageItem(1, par3EntityLiving);
050            return true;
051        }
052    
053        public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving)
054        {
055            if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D)
056            {
057                par1ItemStack.damageItem(2, par7EntityLiving);
058            }
059    
060            return true;
061        }
062    
063        /**
064         * Returns the damage against a given entity.
065         */
066        public int getDamageVsEntity(Entity par1Entity)
067        {
068            return this.weaponDamage;
069        }
070    
071        @SideOnly(Side.CLIENT)
072    
073        /**
074         * Returns True is the item is renderer in full 3D when hold.
075         */
076        public boolean isFull3D()
077        {
078            return true;
079        }
080    
081        /**
082         * returns the action that specifies what animation to play when the items is being used
083         */
084        public EnumAction getItemUseAction(ItemStack par1ItemStack)
085        {
086            return EnumAction.block;
087        }
088    
089        /**
090         * How long it takes to use or consume an item
091         */
092        public int getMaxItemUseDuration(ItemStack par1ItemStack)
093        {
094            return 72000;
095        }
096    
097        /**
098         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
099         */
100        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
101        {
102            par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
103            return par1ItemStack;
104        }
105    
106        /**
107         * Returns if the item (tool) can harvest results from the block type.
108         */
109        public boolean canHarvestBlock(Block par1Block)
110        {
111            return par1Block.blockID == Block.web.blockID;
112        }
113    
114        /**
115         * Return the enchantability factor of the item, most of the time is based on material.
116         */
117        public int getItemEnchantability()
118        {
119            return this.toolMaterial.getEnchantability();
120        }
121    
122        public String func_77825_f()
123        {
124            return this.toolMaterial.toString();
125        }
126    
127        /**
128         * Return whether this item is repairable in an anvil.
129         */
130        public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
131        {
132            return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
133        }
134    }