Advertisement
Jup_

Untitled

Nov 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package com.mraof.minestuck.item.weapon;
  2.  
  3. import com.mraof.minestuck.item.TabMinestuck;
  4.  
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.init.SoundEvents;
  8. import net.minecraft.item.EnumAction;
  9. import net.minecraft.item.ItemFood;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.util.ActionResult;
  12. import net.minecraft.util.EnumActionResult;
  13. import net.minecraft.util.EnumHand;
  14. import net.minecraft.util.SoundCategory;
  15. import net.minecraft.world.World;
  16.  
  17. public class ItemConsumableWeapon extends ItemWeapon {
  18. private final int healAmount;
  19. private final float saturationModifier;
  20. public ItemConsumableWeapon(int maxUses, double damageVsEntity, double weaponSpeed, int enchantability, String name, int amount, float saturation) {
  21. super(maxUses, damageVsEntity, weaponSpeed, enchantability, name);
  22. this.setCreativeTab(TabMinestuck.instance);
  23. this.healAmount = amount;
  24. this.saturationModifier = saturation;
  25. }
  26.  
  27. @Override
  28. public int getMaxItemUseDuration(ItemStack stack)
  29. {
  30. return 32;
  31. }
  32.  
  33. @Override
  34. public EnumAction getItemUseAction(ItemStack stack)
  35. {
  36. return EnumAction.EAT;
  37. }
  38.  
  39. @Override
  40. public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving)
  41. {
  42. stack.damageItem(50, entityLiving);
  43.  
  44. if(entityLiving instanceof EntityPlayer)
  45. {
  46. EntityPlayer entityplayer = (EntityPlayer)entityLiving;
  47. entityplayer.getFoodStats().addStats(healAmount, saturationModifier);
  48. worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
  49. }
  50. return stack;
  51. }
  52.  
  53. public void addStats(ItemFood foodItem, ItemStack stack)
  54. {
  55. this.addStats(foodItem.getHealAmount(stack), foodItem.getSaturationModifier(stack));
  56. }
  57.  
  58. @Override
  59. public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  60. {
  61. playerIn.setActiveHand(handIn);
  62. return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement