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.setTabToDisplayOn(CreativeTabs.tabCombat); 018 this.weaponDamage = 4 + par2EnumToolMaterial.getDamageVsEntity(); 019 } 020 021 /** 022 * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if 023 * sword 024 */ 025 public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) 026 { 027 return par2Block.blockID == Block.web.blockID ? 15.0F : 1.5F; 028 } 029 030 /** 031 * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise 032 * the damage on the stack. 033 */ 034 public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving) 035 { 036 par1ItemStack.damageItem(1, par3EntityLiving); 037 return true; 038 } 039 040 public boolean func_77660_a(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLiving par7EntityLiving) 041 { 042 if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D) 043 { 044 par1ItemStack.damageItem(2, par7EntityLiving); 045 } 046 047 return true; 048 } 049 050 /** 051 * Returns the damage against a given entity. 052 */ 053 public int getDamageVsEntity(Entity par1Entity) 054 { 055 return this.weaponDamage; 056 } 057 058 @SideOnly(Side.CLIENT) 059 060 /** 061 * Returns True is the item is renderer in full 3D when hold. 062 */ 063 public boolean isFull3D() 064 { 065 return true; 066 } 067 068 /** 069 * returns the action that specifies what animation to play when the items is being used 070 */ 071 public EnumAction getItemUseAction(ItemStack par1ItemStack) 072 { 073 return EnumAction.block; 074 } 075 076 /** 077 * How long it takes to use or consume an item 078 */ 079 public int getMaxItemUseDuration(ItemStack par1ItemStack) 080 { 081 return 72000; 082 } 083 084 /** 085 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer 086 */ 087 public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) 088 { 089 par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); 090 return par1ItemStack; 091 } 092 093 /** 094 * Returns if the item (tool) can harvest results from the block type. 095 */ 096 public boolean canHarvestBlock(Block par1Block) 097 { 098 return par1Block.blockID == Block.web.blockID; 099 } 100 101 /** 102 * Return the enchantability factor of the item, most of the time is based on material. 103 */ 104 public int getItemEnchantability() 105 { 106 return this.toolMaterial.getEnchantability(); 107 } 108 109 public String func_77825_f() 110 { 111 return this.toolMaterial.toString(); 112 } 113 }