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
|
2024-10-23 23:35:21 +02:00
|
|
|
index a706f0855fdf88cc9aece3ba00ef574b9cd8bd11..2aee9c2fbe38076317a3de7c3fdbd6988b64b389 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
|
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();
|
2022-10-07 17:22:45 +02:00
|
|
|
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 {
|
2022-10-07 17:22:45 +02:00
|
|
|
}
|
|
|
|
|
2024-10-23 23:35:21 +02:00
|
|
|
if (player.getCooldowns().isOnCooldown(stack)) {
|
2022-10-07 17:22:45 +02:00
|
|
|
- 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());
|
2024-01-18 15:56:25 +01:00
|
|
|
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, blockposition, hitResult.getDirection(), stack, cancelledBlock, cancelledItem, hand, hitResult.getLocation()); // Paper - correctly handle items on cooldown
|
2022-10-07 17:22:45 +02:00
|
|
|
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-24 12:11:32 +02:00
|
|
|
index f54a4c263eeb4df40c72c20c3c480ce74718a718..ea0241de1a7ef64059cddcb43c41f56b91901897 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
|
2024-10-23 23:35:21 +02:00
|
|
|
@@ -555,6 +555,12 @@ public class CraftEventFactory {
|
2022-10-07 17:22:45 +02:00
|
|
|
}
|
|
|
|
|
2023-06-18 13:03:18 +02:00
|
|
|
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
|
2023-06-23 18:03:43 +02:00
|
|
|
+ return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, false, hand, targetPos);
|
2023-06-18 13:03:18 +02:00
|
|
|
+ }
|
2024-02-01 10:15:57 +01:00
|
|
|
+
|
2023-06-18 13:03:18 +02: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
|
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
|
|
|
|
2024-10-23 23:35:21 +02:00
|
|
|
@@ -589,6 +595,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;
|