Advertisement
jayhillx

butterfly; mobinteract

Oct 19th, 2022
1,528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /** Handles butterflies saving given flowers. */
  2.     public InteractionResult mobInteract(Player player, InteractionHand hand) {
  3.         Item item = player.getItemInHand(hand).getItem();
  4.         ItemStack stack = item.getDefaultInstance();
  5.  
  6.         if (stack.is(ItemTags.FLOWERS)) {
  7.             this.setSavedFlower(Block.byItem(item));
  8.  
  9.             // Success Particle
  10.             if (this.level.isClientSide) {
  11.                 for (int i = 0; i < 7; ++i) {
  12.                     double d = this.random.nextGaussian() * 0.02D;
  13.                     this.level.addParticle(ParticleTypes.HAPPY_VILLAGER, this.getRandomX(1.0D), this.getRandomY() + 0.5D, this.getRandomZ(1.0D), d, d, d);
  14.                 }
  15.             }
  16.             return InteractionResult.SUCCESS;
  17.         } else {
  18.             return InteractionResult.PASS;
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement