aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLulu13022002 <[email protected]>2024-07-15 17:07:07 +0200
committerGitHub <[email protected]>2024-07-15 17:07:07 +0200
commitaa929d66667e58929097dee3fd9499095c989392 (patch)
treecfebd91b76a89c011870ce9d5449696193c19b2d
parent05e5865da30d072e729d4681d02a316f6ae072fa (diff)
downloadPaper-aa929d66667e58929097dee3fd9499095c989392.tar.gz
Paper-aa929d66667e58929097dee3fd9499095c989392.zip
Call PlayerLaunchProjectileEvent for wind charge (#10911)
-rw-r--r--patches/server/0215-PlayerLaunchProjectileEvent.patch44
1 files changed, 44 insertions, 0 deletions
diff --git a/patches/server/0215-PlayerLaunchProjectileEvent.patch b/patches/server/0215-PlayerLaunchProjectileEvent.patch
index 93e96a0bf9..be34c111d3 100644
--- a/patches/server/0215-PlayerLaunchProjectileEvent.patch
+++ b/patches/server/0215-PlayerLaunchProjectileEvent.patch
@@ -317,3 +317,47 @@ index 2d34f206b4b02d5f2ee35101233afc6b4f58a579..f1b2d388a1a40a1d909a2e726f32d6c1
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 6222e867bb959fab05bcd8f2114ab00b26847c3e..eed0d754e9a3c7c94614e0fd54651500e0612ea8 100644
+--- a/src/main/java/net/minecraft/world/item/WindChargeItem.java
++++ b/src/main/java/net/minecraft/world/item/WindChargeItem.java
+@@ -24,10 +24,26 @@ public class WindChargeItem extends Item implements ProjectileItem {
+
+ @Override
+ public InteractionResultHolder<ItemStack> 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(
+@@ -40,10 +56,9 @@ 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());
+ }
+