From 084923b9acd8b8a1fee8c01cc654dffada6135c7 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:07:07 +0200 Subject: [PATCH] Call PlayerLaunchProjectileEvent for wind charge (#10911) --- .../server/PlayerLaunchProjectileEvent.patch | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/patches/server/PlayerLaunchProjectileEvent.patch b/patches/server/PlayerLaunchProjectileEvent.patch index 239f18a044..0ad76b9169 100644 --- a/patches/server/PlayerLaunchProjectileEvent.patch +++ b/patches/server/PlayerLaunchProjectileEvent.patch @@ -317,3 +317,47 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 entityhuman.getInventory().removeItem(stack); } // CraftBukkit start - SPIGOT-5458 also need in this branch :( +diff --git a/src/main/java/net/minecraft/world/item/WindChargeItem.java b/src/main/java/net/minecraft/world/item/WindChargeItem.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/item/WindChargeItem.java ++++ b/src/main/java/net/minecraft/world/item/WindChargeItem.java +@@ -0,0 +0,0 @@ public class WindChargeItem extends Item implements ProjectileItem { + + @Override + public InteractionResultHolder use(Level world, Player user, InteractionHand hand) { ++ ItemStack itemStack = user.getItemInHand(hand); // Paper - PlayerLaunchProjectileEvent; moved from below ++ boolean shouldConsume = true; // Paper - PlayerLaunchProjectileEvent + if (!world.isClientSide()) { + WindCharge windCharge = new WindCharge(user, world, user.position().x(), user.getEyePosition().y(), user.position().z()); + windCharge.shootFromRotation(user, user.getXRot(), user.getYRot(), 0.0F, 1.5F, 1.0F); +- world.addFreshEntity(windCharge); ++ // Paper start - PlayerLaunchProjectileEvent ++ com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent event = new com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent((org.bukkit.entity.Player) user.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemStack), (org.bukkit.entity.Projectile) windCharge.getBukkitEntity()); ++ if (!event.callEvent() || !world.addFreshEntity(windCharge)) { ++ user.containerMenu.sendAllDataToRemote(); ++ if (user instanceof net.minecraft.server.level.ServerPlayer player) { ++ player.connection.send(new net.minecraft.network.protocol.game.ClientboundCooldownPacket(this, 0)); // prevent visual desync of cooldown on the slot ++ } ++ return InteractionResultHolder.fail(itemStack); ++ } ++ ++ shouldConsume = event.shouldConsume(); ++ if (!shouldConsume && !user.hasInfiniteMaterials()) { ++ user.containerMenu.sendAllDataToRemote(); ++ } ++ // Paper end - PlayerLaunchProjectileEvent + } + + world.playSound( +@@ -0,0 +0,0 @@ public class WindChargeItem extends Item implements ProjectileItem { + 0.5F, + 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F) + ); +- ItemStack itemStack = user.getItemInHand(hand); + user.getCooldowns().addCooldown(this, 10); + user.awardStat(Stats.ITEM_USED.get(this)); +- itemStack.consume(1, user); ++ if (shouldConsume) itemStack.consume(1, user); // Paper - PlayerLaunchProjectileEvent + return InteractionResultHolder.sidedSuccess(itemStack, world.isClientSide()); + } +