From 3a2229c5f306c4a7285d516013f5f425807efd34 Mon Sep 17 00:00:00 2001 From: caramel Date: Sun, 10 Dec 2023 19:02:24 +0900 Subject: [PATCH] Fix `PlayerInteractEvent#getClickedBlock()` returning wrong block in adventure mode (#10019) --- .../Fix-interact-event-not-being-called-sometimes.patch | 2 +- patches/server/MC-Utils.patch | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/patches/server/Fix-interact-event-not-being-called-sometimes.patch b/patches/server/Fix-interact-event-not-being-called-sometimes.patch index 30fdb02080..5e66917c31 100644 --- a/patches/server/Fix-interact-event-not-being-called-sometimes.patch +++ b/patches/server/Fix-interact-event-not-being-called-sometimes.patch @@ -38,7 +38,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } else { // Paper start - Fix interact event not being called sometimes + GameType gameType = this.player.gameMode.getGameModeForPlayer(); + if (gameType == GameType.ADVENTURE && result.getHitBlock() != null) { -+ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, io.papermc.paper.util.MCUtil.toBlockPosition(result.getHitPosition()), org.bukkit.craftbukkit.block.CraftBlock.blockFaceToNotch(result.getHitBlockFace()), this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND); ++ CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, ((org.bukkit.craftbukkit.block.CraftBlock) result.getHitBlock()).getPosition(), org.bukkit.craftbukkit.block.CraftBlock.blockFaceToNotch(result.getHitBlockFace()), this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND); + } else if (gameType != GameType.CREATIVE && result.getHitEntity() != null && origin.toVector().distanceSquared(result.getHitPosition()) > 3.0D * 3.0D) { + CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.getInventory().getSelected(), InteractionHand.MAIN_HAND); + } diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index e8ca4726d1..5a695142c9 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -3507,7 +3507,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.util.Waitable; -+import org.bukkit.util.Vector; +import org.spigotmc.AsyncCatcher; + +import javax.annotation.Nonnull; @@ -3960,10 +3959,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return new BlockPos(pos.blockX(), pos.blockY(), pos.blockZ()); + } + -+ public static BlockPos toBlockPosition(Vector vec) { -+ return new BlockPos(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()); -+ } -+ + public static FinePosition toPosition(Vec3 vector) { + return Position.fine(vector.x, vector.y, vector.z); + }