From 325ba14ca5f9fd53da37c536c099c91c21025a19 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 11 Sep 2021 22:18:44 +0200 Subject: [PATCH] Improve interact distance check (#6591) --- ...ove-range-check-for-block-placing-up.patch | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/patches/server/Move-range-check-for-block-placing-up.patch b/patches/server/Move-range-check-for-block-placing-up.patch index cbdebb889f..45bd38a99d 100644 --- a/patches/server/Move-range-check-for-block-placing-up.patch +++ b/patches/server/Move-range-check-for-block-placing-up.patch @@ -8,14 +8,30 @@ diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListener index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser + } + // Spigot end + ++ // Paper start ++ private boolean isOutsideOfReach(double x, double y, double z) { ++ Location eyeLoc = this.getCraftPlayer().getEyeLocation(); ++ double reachDistance = NumberConversions.square(eyeLoc.getX() - x) + NumberConversions.square(eyeLoc.getY() - y) + NumberConversions.square(eyeLoc.getZ() - z); ++ return reachDistance > (this.getCraftPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED); ++ } ++ // Paper end ++ + @Override + public void handleUseItemOn(ServerboundUseItemOnPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser BlockPos blockposition = movingobjectpositionblock.getBlockPos(); Direction enumdirection = movingobjectpositionblock.getDirection(); -+ // Paper start - move check up -+ Location eyeLoc = this.getCraftPlayer().getEyeLocation(); -+ double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ()); -+ if (reachDistance > (this.getCraftPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) { ++ // Paper start - move check up and check actual location as well ++ final Vec3 clickedLocation = movingobjectpositionblock.getLocation(); ++ if (isOutsideOfReach(blockposition.getX(), blockposition.getY(), blockposition.getZ()) ++ || !Double.isFinite(clickedLocation.x) || !Double.isFinite(clickedLocation.y) || !Double.isFinite(clickedLocation.z) ++ || isOutsideOfReach(clickedLocation.x, clickedLocation.y, clickedLocation.z)) { + return; + } + // Paper end - move check up