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