package net.minecraft.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; public class ItemSword extends Item { private int weaponDamage; private final EnumToolMaterial toolMaterial; public ItemSword(int par1, EnumToolMaterial par2EnumToolMaterial) { super(par1); this.toolMaterial = par2EnumToolMaterial; this.maxStackSize = 1; this.setMaxDamage(par2EnumToolMaterial.getMaxUses()); this.setCreativeTab(CreativeTabs.tabCombat); this.weaponDamage = 4 + par2EnumToolMaterial.getDamageVsEntity(); } public int func_82803_g() { return this.toolMaterial.getDamageVsEntity(); } /** * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if * sword */ public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { if (par2Block.blockID == Block.web.blockID) { return 15.0F; } else { Material var3 = par2Block.blockMaterial; return var3 != Material.plants && var3 != Material.vine && var3 != Material.coral && var3 != Material.leaves && var3 != Material.pumpkin ? 1.0F : 1.5F; } } /** * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise * the damage on the stack. */ public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving) { par1ItemStack.damageItem(1, par3EntityLiving); return true; } public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving) { if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D) { par1ItemStack.damageItem(2, par7EntityLiving); } return true; } /** * Returns the damage against a given entity. */ public int getDamageVsEntity(Entity par1Entity) { return this.weaponDamage; } @SideOnly(Side.CLIENT) /** * Returns True is the item is renderer in full 3D when hold. */ public boolean isFull3D() { return true; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.block; } /** * How long it takes to use or consume an item */ public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); return par1ItemStack; } /** * Returns if the item (tool) can harvest results from the block type. */ public boolean canHarvestBlock(Block par1Block) { return par1Block.blockID == Block.web.blockID; } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return this.toolMaterial.getEnchantability(); } public String func_77825_f() { return this.toolMaterial.toString(); } /** * Return whether this item is repairable in an anvil. */ public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } }