PaperMC/paper-server/patches/sources/net/minecraft/world/item/ThrowablePotionItem.java.patch

32 lines
1.8 KiB
Diff
Raw Normal View History

2024-12-14 21:50:20 +01:00
--- a/net/minecraft/world/item/ThrowablePotionItem.java
+++ b/net/minecraft/world/item/ThrowablePotionItem.java
2024-12-15 15:55:13 +01:00
@@ -22,11 +_,25 @@
2024-12-14 21:50:20 +01:00
public InteractionResult use(Level level, Player player, InteractionHand hand) {
ItemStack itemInHand = player.getItemInHand(hand);
if (level instanceof ServerLevel serverLevel) {
- Projectile.spawnProjectileFromRotation(ThrownPotion::new, serverLevel, itemInHand, player, -20.0F, PROJECTILE_SHOOT_POWER, 1.0F);
+ // Paper start - PlayerLaunchProjectileEvent
+ final Projectile.Delayed<ThrownPotion> thrownPotion = Projectile.spawnProjectileFromRotationDelayed(ThrownPotion::new, serverLevel, itemInHand, player, -20.0F, PROJECTILE_SHOOT_POWER, 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) thrownPotion.projectile().getBukkitEntity());
+ if (event.callEvent() && thrownPotion.attemptSpawn()) {
+ if (event.shouldConsume()) {
+ itemInHand.consume(1, player);
2024-12-15 15:55:13 +01:00
+ } else {
+ player.containerMenu.sendAllDataToRemote();
2024-12-14 21:50:20 +01:00
+ }
+
+ player.awardStat(Stats.ITEM_USED.get(this));
+ } else {
2024-12-15 15:55:13 +01:00
+ player.containerMenu.sendAllDataToRemote();
2024-12-14 21:50:20 +01:00
+ return InteractionResult.FAIL;
+ }
+ // Paper end - PlayerLaunchProjectileEvent
}
- player.awardStat(Stats.ITEM_USED.get(this));
- itemInHand.consume(1, player);
+ // Paper - PlayerLaunchProjectileEvent - move up
return InteractionResult.SUCCESS;
}