Zapfox

Untitled

Nov 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  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.block.state.IBlockState;
  7. import net.minecraft.creativetab.CreativeTabs;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.entity.SharedMonsterAttributes;
  10. import net.minecraft.entity.ai.attributes.AttributeModifier;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.inventory.EntityEquipmentSlot;
  13. import net.minecraft.util.math.BlockPos;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.fml.relauncher.Side;
  16. import net.minecraftforge.fml.relauncher.SideOnly;
  17.  
  18. public class ItemSword extends Item
  19. {
  20. private final float attackDamage;
  21. private final Item.ToolMaterial material;
  22.  
  23. public ItemSword(Item.ToolMaterial material)
  24. {
  25. this.material = material;
  26. this.maxStackSize = 1;
  27. this.setMaxDamage(material.getMaxUses());
  28. this.setCreativeTab(CreativeTabs.COMBAT);
  29. this.attackDamage = 3.0F + material.getDamageVsEntity();
  30. }
  31.  
  32. /**
  33. * Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points.
  34. */
  35. public float getDamageVsEntity()
  36. {
  37. return this.material.getDamageVsEntity();
  38. }
  39.  
  40. public float getStrVsBlock(ItemStack stack, IBlockState state)
  41. {
  42. Block block = state.getBlock();
  43.  
  44. if (block == Blocks.WEB)
  45. {
  46. return 15.0F;
  47. }
  48. else
  49. {
  50. Material material = state.getMaterial();
  51. return material != Material.PLANTS && material != Material.VINE && material != Material.CORAL && material != Material.LEAVES && material != Material.GOURD ? 1.0F : 1.5F;
  52. }
  53. }
  54.  
  55. /**
  56. * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
  57. * the damage on the stack.
  58. */
  59. public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
  60. {
  61. stack.damageItem(1, attacker);
  62. return true;
  63. }
  64.  
  65. /**
  66. * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
  67. */
  68. public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
  69. {
  70. if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
  71. {
  72. stack.damageItem(2, entityLiving);
  73. }
  74.  
  75. return true;
  76. }
  77.  
  78. /**
  79. * Check whether this Item can harvest the given Block
  80. */
  81. public boolean canHarvestBlock(IBlockState blockIn)
  82. {
  83. return blockIn.getBlock() == Blocks.WEB;
  84. }
  85.  
  86. /**
  87. * Returns True is the item is renderer in full 3D when hold.
  88. */
  89. @SideOnly(Side.CLIENT)
  90. public boolean isFull3D()
  91. {
  92. return true;
  93. }
  94.  
  95. /**
  96. * Return the enchantability factor of the item, most of the time is based on material.
  97. */
  98. public int getItemEnchantability()
  99. {
  100. return this.material.getEnchantability();
  101. }
  102.  
  103. /**
  104. * Return the name for this tool's material.
  105. */
  106. public String getToolMaterialName()
  107. {
  108. return this.material.toString();
  109. }
  110.  
  111. /**
  112. * Return whether this item is repairable in an anvil.
  113. */
  114. public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
  115. {
  116. ItemStack mat = this.material.getRepairItemStack();
  117. if (!mat.isEmpty() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, repair, false)) return true;
  118. return super.getIsRepairable(toRepair, repair);
  119. }
  120.  
  121. /**
  122. * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage.
  123. */
  124. public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
  125. {
  126. Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
  127.  
  128. if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
  129. {
  130. multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)this.attackDamage, 0));
  131. multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -2.4000000953674316D, 0));
  132. }
  133.  
  134. return multimap;
  135. }
  136. }
Add Comment
Please, Sign In to add comment