aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0477-Move-range-check-for-block-placing-up.patch
blob: 5f4bf621565e8f56f5d1d4405fd6a2ed45252209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Wed, 15 Jul 2020 19:34:11 -0700
Subject: [PATCH] Move range check for block placing up


diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index acffb2c8a4f864da16c65b83a320d8b181bdc2d7..938e6ee89bdb398dc4e2ce1682727c0e63f28c26 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1667,6 +1667,14 @@ 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());
@@ -1679,17 +1687,22 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
         BlockPos blockposition = movingobjectpositionblock.getBlockPos();
         Direction enumdirection = movingobjectpositionblock.getDirection();
 
+        // Paper start - move check up and check actual location as well
+        final Vec3 clickedLocation = movingobjectpositionblock.getLocation();
+        if (isOutsideOfReach(blockposition.getX() + 0.5D, blockposition.getY() + 0.5D, blockposition.getZ() + 0.5D)
+            || !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
+
         this.player.resetLastActionTime();
         int i = this.player.level.getMaxBuildHeight();
 
         if (blockposition.getY() < i) {
             if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) {
                 // CraftBukkit start - Check if we can actually do something over this large a distance
-                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 ? ServerGamePacketListenerImpl.CREATIVE_PLACE_DISTANCE_SQUARED : ServerGamePacketListenerImpl.SURVIVAL_PLACE_DISTANCE_SQUARED)) {
-                    return;
-                }
+                // Paper - move check up
                 this.player.stopUsingItem(); // SPIGOT-4706
                 // CraftBukkit end
                 InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);