--- a/net/minecraft/world/item/ExperienceBottleItem.java +++ b/net/minecraft/world/item/ExperienceBottleItem.java @@ -21,22 +_,36 @@ @Override public InteractionResult use(Level level, Player player, InteractionHand hand) { ItemStack itemInHand = player.getItemInHand(hand); - level.playSound( - null, - player.getX(), - player.getY(), - player.getZ(), - SoundEvents.EXPERIENCE_BOTTLE_THROW, - SoundSource.NEUTRAL, - 0.5F, - 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F) - ); + // Paper - PlayerLaunchProjectileEvent - moved down if (level instanceof ServerLevel serverLevel) { - Projectile.spawnProjectileFromRotation(ThrownExperienceBottle::new, serverLevel, itemInHand, player, -20.0F, 0.7F, 1.0F); + // Paper start - PlayerLaunchProjectileEvent + final Projectile.Delayed thrownExperienceBottle = Projectile.spawnProjectileFromRotationDelayed(ThrownExperienceBottle::new, serverLevel, itemInHand, player, -20.0F, 0.7F, 1.0F); + com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemInHand), (org.bukkit.entity.Projectile) thrownExperienceBottle.projectile().getBukkitEntity()); + if (event.callEvent() && thrownExperienceBottle.attemptSpawn()) { + if (event.shouldConsume()) { + itemInHand.consume(1, player); + } else { + player.containerMenu.sendAllDataToRemote(); + } + + level.playSound( + null, + player.getX(), + player.getY(), + player.getZ(), + SoundEvents.EXPERIENCE_BOTTLE_THROW, + SoundSource.NEUTRAL, + 0.5F, + 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F) + ); + } else { + player.containerMenu.sendAllDataToRemote(); + return InteractionResult.FAIL; + } + // Paper end - PlayerLaunchProjectileEvent } - player.awardStat(Stats.ITEM_USED.get(this)); - itemInHand.consume(1, player); + // Paper - PlayerLaunchProjectileEvent - moved up return InteractionResult.SUCCESS; }