Paper/patches/server/0745-Correctly-handle-interactions-with-items-on-cooldown.patch

61 lines
3.6 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 16 Jun 2022 21:57:02 -0700
Subject: [PATCH] Correctly handle interactions with items on cooldown
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2024-10-23 23:35:21 +02:00
index a706f0855fdf88cc9aece3ba00ef574b9cd8bd11..2aee9c2fbe38076317a3de7c3fdbd6988b64b389 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2024-10-23 23:35:21 +02:00
@@ -520,6 +520,7 @@ public class ServerPlayerGameMode {
2024-04-24 23:23:56 +02:00
BlockPos blockposition = hitResult.getBlockPos();
BlockState iblockdata = world.getBlockState(blockposition);
boolean cancelledBlock = false;
+ boolean cancelledItem = false; // Paper - correctly handle items on cooldown
2022-12-07 23:05:32 +01:00
if (!iblockdata.getBlock().isEnabled(world.enabledFeatures())) {
return InteractionResult.FAIL;
2024-10-23 23:35:21 +02:00
@@ -529,10 +530,10 @@ public class ServerPlayerGameMode {
}
2024-10-23 23:35:21 +02:00
if (player.getCooldowns().isOnCooldown(stack)) {
- cancelledBlock = true;
+ cancelledItem = true; // Paper - correctly handle items on cooldown
}
- PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, hand, hitResult.getLocation());
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, cancelledItem, hand, hitResult.getLocation()); // Paper - correctly handle items on cooldown
this.firedInteract = true;
this.interactResult = event.useItemInHand() == Event.Result.DENY;
this.interactPosition = blockposition.immutable();
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-10-23 23:35:21 +02:00
index f7e26e381c2a2fec70cc2df01a12e7dbeeab48cd..cb05a94f2856a8bfb478bceb7c8712bc5e7ad5c2 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-10-23 23:35:21 +02:00
@@ -555,6 +555,12 @@ public class CraftEventFactory {
}
public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand, Vec3 targetPos) {
2024-02-01 10:15:57 +01:00
+ // Paper start - cancelledItem param
+ return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, false, hand, targetPos);
+ }
2024-02-01 10:15:57 +01:00
+
+ public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, boolean cancelledItem, InteractionHand hand, Vec3 targetPos) {
+ // Paper end - cancelledItem param
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
2024-10-23 23:35:21 +02:00
@@ -589,6 +595,11 @@ public class CraftEventFactory {
if (cancelledBlock) {
event.setUseInteractedBlock(Event.Result.DENY);
}
+ // Paper start
+ if (cancelledItem) {
+ event.setUseItemInHand(Result.DENY);
+ }
+ // Paper end
craftServer.getPluginManager().callEvent(event);
return event;