2022-10-07 17:22:45 +02:00
|
|
|
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
|
2023-06-18 13:03:18 +02:00
|
|
|
index 6a5e3649d9843d85eceb0eae225200fa2551e844..1635fee928d64f4d2c336dca6675ed4641918830 100644
|
2022-10-07 17:22:45 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
2023-06-09 06:29:58 +02:00
|
|
|
@@ -521,6 +521,7 @@ public class ServerPlayerGameMode {
|
2022-10-07 17:22:45 +02:00
|
|
|
BlockState iblockdata = world.getBlockState(blockposition);
|
|
|
|
InteractionResult enuminteractionresult = InteractionResult.PASS;
|
|
|
|
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;
|
2023-06-09 06:29:58 +02:00
|
|
|
@@ -530,10 +531,10 @@ public class ServerPlayerGameMode {
|
2022-10-07 17:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (player.getCooldowns().isOnCooldown(stack.getItem())) {
|
|
|
|
- cancelledBlock = true;
|
|
|
|
+ cancelledItem = true; // Paper - correctly handle items on cooldown
|
|
|
|
}
|
|
|
|
|
2023-06-18 13:03:18 +02:00
|
|
|
- PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, hand, hitResult.getLocation());
|
2022-10-07 17:22:45 +02:00
|
|
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, cancelledItem, hand, hitResult.getLocation()); // Paper
|
|
|
|
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
|
2023-06-18 13:03:18 +02:00
|
|
|
index 9201e143ff520126c27a649bba62b359a01669c4..e813b58d724b9e5900df68f763ad0b59c84e47f4 100644
|
2022-10-07 17:22:45 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2023-06-18 13:03:18 +02:00
|
|
|
@@ -512,7 +512,13 @@ public class CraftEventFactory {
|
|
|
|
return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, false, hand, null);
|
2022-10-07 17:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+
|
2023-06-18 13:03:18 +02:00
|
|
|
+ // Paper start - cancelledItem param
|
|
|
|
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) {
|
|
|
|
+ return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, false, false, hand, null);
|
|
|
|
+ }
|
|
|
|
+ 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
|
2022-10-07 17:22:45 +02:00
|
|
|
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
|
2023-06-18 13:03:18 +02:00
|
|
|
|
|
|
|
@@ -547,6 +553,11 @@ public class CraftEventFactory {
|
2022-10-07 17:22:45 +02:00
|
|
|
if (cancelledBlock) {
|
|
|
|
event.setUseInteractedBlock(Event.Result.DENY);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ if (cancelledItem) {
|
|
|
|
+ event.setUseItemInHand(Result.DENY);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
craftServer.getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return event;
|