Advertisement
cjcj55

Edible Experience Item Class

Nov 4th, 2020
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.cjcj55.chrispymod.objects.items;
  2.  
  3. import net.minecraft.entity.item.ExperienceOrbEntity;
  4. import net.minecraft.entity.player.PlayerEntity;
  5. import net.minecraft.item.Item;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.stats.Stats;
  8. import net.minecraft.util.ActionResult;
  9. import net.minecraft.util.Hand;
  10. import net.minecraft.util.SoundCategory;
  11. import net.minecraft.util.SoundEvents;
  12. import net.minecraft.world.World;
  13.  
  14. public class EdibleExperienceItem extends Item
  15. {
  16. public EdibleExperienceItem(Properties properties)
  17. {
  18. super(properties);
  19. }
  20.  
  21. public ActionResult<ItemStack> dropXP(World world, PlayerEntity player, Hand hand)
  22. {
  23. ItemStack stack = player.getHeldItem(hand);
  24. world.playSound((PlayerEntity)null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
  25. if (!world.isRemote)
  26. {
  27. int amount = 8;
  28. ExperienceOrbEntity xpEntity = new ExperienceOrbEntity(world, player.getPosX(), player.getPosY(), player.getPosZ(), amount);
  29.  
  30. world.addEntity(xpEntity);
  31.  
  32. player.addStat(Stats.ITEM_USED.get(this));
  33. if (!player.abilities.isCreativeMode)
  34. {
  35. stack.damageItem(1, player, (p_219998_1_) -> {
  36. p_219998_1_.sendBreakAnimation(hand);
  37. });
  38. }
  39.  
  40. }
  41.  
  42. return ActionResult.resultSuccess(stack);
  43.  
  44. }
  45.  
  46. }
Advertisement
RAW Paste Data Copied
Advertisement