mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
61 lines
3.6 KiB
Diff
61 lines
3.6 KiB
Diff
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
|
|
index da8a60fbbba3866780615e65d6e242774a965bc6..88b71210d0845e8a4a2cd424ba238c4b5e27933b 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
|
|
@@ -514,6 +514,7 @@ public class ServerPlayerGameMode {
|
|
BlockState iblockdata = world.getBlockState(blockposition);
|
|
InteractionResult enuminteractionresult = InteractionResult.PASS;
|
|
boolean cancelledBlock = false;
|
|
+ boolean cancelledItem = false; // Paper - correctly handle items on cooldown
|
|
|
|
if (!iblockdata.getBlock().isEnabled(world.enabledFeatures())) {
|
|
return InteractionResult.FAIL;
|
|
@@ -523,10 +524,10 @@ public class ServerPlayerGameMode {
|
|
}
|
|
|
|
if (player.getCooldowns().isOnCooldown(stack.getItem())) {
|
|
- 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
|
|
index 531eeb68bc0623b3c71e67789603ab7946e05818..a1860e21fd53b801ffd651cd27f5a8f9fcd02ee0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -544,6 +544,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) {
|
|
+ // Paper start - cancelledItem param
|
|
+ return CraftEventFactory.callPlayerInteractEvent(who, action, position, direction, itemstack, cancelledBlock, false, hand, targetPos);
|
|
+ }
|
|
+
|
|
+ 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);
|
|
|
|
@@ -578,6 +584,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;
|