| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import com.google.common.collect.Multimap;
|
| 4 | import net.minecraft.block.Block;
|
| 5 | import net.minecraft.block.material.Material;
|
| 6 | import net.minecraft.creativetab.CreativeTabs;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 9 | import net.minecraft.entity.ai.attributes.AttributeModifier;
|
| 10 | import net.minecraft.entity.player.EntityPlayer;
|
| 11 | import net.minecraft.init.Blocks;
|
| 12 | import net.minecraft.util.BlockPos;
|
| 13 | import net.minecraft.world.World;
|
| 14 |
|
| 15 | public class ItemSword extends Item
|
| 16 | {
|
| 17 | private float attackDamage;
|
| 18 | private final Item.ToolMaterial material;
|
| 19 |
|
| 20 | public ItemSword(Item.ToolMaterial material)
|
| 21 | {
|
| 22 | this.material = material;
|
| 23 | this.maxStackSize = 1;
|
| 24 | this.setMaxDamage(material.getMaxUses());
|
| 25 | this.setCreativeTab(CreativeTabs.tabCombat);
|
| 26 | this.attackDamage = 4.0F + material.getDamageVsEntity();
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points.
|
| 31 | */
|
| 32 | public float getDamageVsEntity()
|
| 33 | {
|
| 34 | return this.material.getDamageVsEntity();
|
| 35 | }
|
| 36 |
|
| 37 | public float getStrVsBlock(ItemStack stack, Block state)
|
| 38 | {
|
| 39 | if (state == Blocks.web)
|
| 40 | {
|
| 41 | return 15.0F;
|
| 42 | }
|
| 43 | else
|
| 44 | {
|
| 45 | Material material = state.getMaterial();
|
| 46 | return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 1.0F : 1.5F;
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | /**
|
| 51 | * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
| 52 | * the damage on the stack.
|
| 53 | */
|
| 54 | public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
| 55 | {
|
| 56 | stack.damageItem(1, attacker);
|
| 57 | return true;
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
| 62 | */
|
| 63 | public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
|
| 64 | {
|
| 65 | if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
|
| 66 | {
|
| 67 | stack.damageItem(2, playerIn);
|
| 68 | }
|
| 69 |
|
| 70 | return true;
|
| 71 | }
|
| 72 |
|
| 73 | /**
|
| 74 | * Returns True is the item is renderer in full 3D when hold.
|
| 75 | */
|
| 76 | public boolean isFull3D()
|
| 77 | {
|
| 78 | return true;
|
| 79 | }
|
| 80 |
|
| 81 | /**
|
| 82 | * returns the action that specifies what animation to play when the items is being used
|
| 83 | */
|
| 84 | public EnumAction getItemUseAction(ItemStack stack)
|
| 85 | {
|
| 86 | return EnumAction.BLOCK;
|
| 87 | }
|
| 88 |
|
| 89 | /**
|
| 90 | * How long it takes to use or consume an item
|
| 91 | */
|
| 92 | public int getMaxItemUseDuration(ItemStack stack)
|
| 93 | {
|
| 94 | return 72000;
|
| 95 | }
|
| 96 |
|
| 97 | /**
|
| 98 | * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
| 99 | */
|
| 100 | public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
|
| 101 | {
|
| 102 | playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
| 103 | return itemStackIn;
|
| 104 | }
|
| 105 |
|
| 106 | /**
|
| 107 | * Check whether this Item can harvest the given Block
|
| 108 | */
|
| 109 | public boolean canHarvestBlock(Block blockIn)
|
| 110 | {
|
| 111 | return blockIn == Blocks.web;
|
| 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.material.getEnchantability();
|
| 120 | }
|
| 121 |
|
| 122 | /**
|
| 123 | * Return the name for this tool's material.
|
| 124 | */
|
| 125 | public String getToolMaterialName()
|
| 126 | {
|
| 127 | return this.material.toString();
|
| 128 | }
|
| 129 |
|
| 130 | /**
|
| 131 | * Return whether this item is repairable in an anvil.
|
| 132 | */
|
| 133 | public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
| 134 | {
|
| 135 | return this.material.getRepairItem() == repair.getItem() ? true : super.getIsRepairable(toRepair, repair);
|
| 136 | }
|
| 137 |
|
| 138 | public Multimap<String, AttributeModifier> getItemAttributeModifiers()
|
| 139 | {
|
| 140 | Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers();
|
| 141 | multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(itemModifierUUID, "Weapon modifier", (double)this.attackDamage, 0));
|
| 142 | return multimap;
|
| 143 | }
|
| 144 | }
|
| 145 |
|