|
| 1 | +From f7a35cf09165c45026d5637261c8162fb9a5de5a Mon Sep 17 00:00:00 2001 |
| 2 | +From: RoccoDev < [email protected]> |
| 3 | +Date: Wed, 12 Nov 2025 22:25:19 +0100 |
| 4 | +Subject: [PATCH] Only skip interact event for same position and item |
| 5 | + |
| 6 | +Fixes SPIGOT-5794. |
| 7 | + |
| 8 | +When recalculating an 'air interact with item' interaction to ray trace for blocks, |
| 9 | +the event would not be fired again if the player's last interaction was with a block, and the ray landed on a different block. |
| 10 | +Instead, the cancel state of the last event would be used again. |
| 11 | + |
| 12 | +diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java |
| 13 | +index c17812626..ee484c88c 100644 |
| 14 | +--- a/src/main/java/net/minecraft/server/PlayerConnection.java |
| 15 | ++++ b/src/main/java/net/minecraft/server/PlayerConnection.java |
| 16 | +@@ -745,13 +745,18 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList |
| 17 | + org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack); |
| 18 | + cancelled = event.useItemInHand() == Event.Result.DENY; |
| 19 | + } else { |
| 20 | +- if (player.playerInteractManager.firedInteract) { |
| 21 | +- player.playerInteractManager.firedInteract = false; |
| 22 | +- cancelled = player.playerInteractManager.interactResult; |
| 23 | ++ // KigPaper - SPIGOT-5794: add block & item stack checks |
| 24 | ++ PlayerInteractManager interactManager = player.playerInteractManager; |
| 25 | ++ if (interactManager.firedInteract && interactManager.interactPosition.equals(movingobjectposition.a()) |
| 26 | ++ && ItemStack.equals(interactManager.interactItemStack, itemstack)) { |
| 27 | ++ cancelled = interactManager.interactResult; |
| 28 | ++ // KigPaper - move down |
| 29 | ++ // interactManager.firedInteract = false; |
| 30 | + } else { |
| 31 | + org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectposition.a(), movingobjectposition.direction, itemstack, true); |
| 32 | + cancelled = event.useItemInHand() == Event.Result.DENY; |
| 33 | + } |
| 34 | ++ interactManager.firedInteract = false; |
| 35 | + } |
| 36 | + |
| 37 | + if (!cancelled) { |
| 38 | +diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java |
| 39 | +index 6f6c1a2ef..f9a4a0d79 100644 |
| 40 | +--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java |
| 41 | ++++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java |
| 42 | +@@ -397,6 +397,10 @@ public class PlayerInteractManager { |
| 43 | + // CraftBukkit start |
| 44 | + public boolean interactResult = false; |
| 45 | + public boolean firedInteract = false; |
| 46 | ++ // KigPaper start - SPIGOT-5794 |
| 47 | ++ public BlockPosition interactPosition; |
| 48 | ++ public ItemStack interactItemStack; |
| 49 | ++ // KigPaper end |
| 50 | + // CraftBukkit end |
| 51 | + |
| 52 | + public boolean interact(EntityHuman entityhuman, World world, ItemStack itemstack, BlockPosition blockposition, EnumDirection enumdirection, float f, float f1, float f2) { |
| 53 | +@@ -463,6 +467,10 @@ public class PlayerInteractManager { |
| 54 | + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityhuman, Action.RIGHT_CLICK_BLOCK, blockposition, enumdirection, itemstack, cancelledBlock); |
| 55 | + firedInteract = true; |
| 56 | + interactResult = event.useItemInHand() == Event.Result.DENY; |
| 57 | ++ // KigPaper start |
| 58 | ++ interactPosition = new BlockPosition(blockposition); |
| 59 | ++ interactItemStack = itemstack != null ? itemstack.cloneItemStack() : null; |
| 60 | ++ // KigPaper end |
| 61 | + |
| 62 | + if (event.useInteractedBlock() == Event.Result.DENY) { |
| 63 | + // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. |
| 64 | +-- |
| 65 | +2.51.0 |
| 66 | + |
0 commit comments