2021-06-11 14:02:28 +02:00
|
|
|
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
|
|
|
|
|
2022-06-08 07:46:52 +02:00
|
|
|
TODO: vanilla has smth very similar already in place starting in 1.19 -MM
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2022-06-07 19:03:07 +02:00
|
|
|
index 6acc4ee50ba32a208930bda89d37f155e3f4835a..0f031b094a180bcce1fe3b388321db838ca4df63 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2022-03-16 16:57:51 +01:00
|
|
|
@@ -1686,6 +1686,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
2021-09-11 22:18:44 +02:00
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
|
|
|
|
+ // Paper start
|
2022-02-12 14:20:33 +01:00
|
|
|
+ private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6;
|
|
|
|
+ private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7;
|
2021-09-11 22:18:44 +02:00
|
|
|
+ private boolean isOutsideOfReach(double x, double y, double z) {
|
|
|
|
+ Location eyeLoc = this.getCraftPlayer().getEyeLocation();
|
2022-02-12 14:20:33 +01:00
|
|
|
+ double reachDistance = org.bukkit.util.NumberConversions.square(eyeLoc.getX() - x) + org.bukkit.util.NumberConversions.square(eyeLoc.getY() - y) + org.bukkit.util.NumberConversions.square(eyeLoc.getZ() - z);
|
2021-09-11 22:18:44 +02:00
|
|
|
+ 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());
|
2022-03-16 16:57:51 +01:00
|
|
|
@@ -1699,6 +1709,15 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
2022-03-01 06:43:03 +01:00
|
|
|
BlockPos blockposition = movingobjectpositionblock.getBlockPos();
|
|
|
|
Vec3 vec3d1 = vec3d.subtract(Vec3.atCenterOf(blockposition));
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2022-02-12 14:20:33 +01:00
|
|
|
+ // Paper start - improve distance check
|
2021-09-11 22:18:44 +02:00
|
|
|
+ final Vec3 clickedLocation = movingobjectpositionblock.getLocation();
|
2021-09-24 10:02:14 +02:00
|
|
|
+ if (isOutsideOfReach(blockposition.getX() + 0.5D, blockposition.getY() + 0.5D, blockposition.getZ() + 0.5D)
|
2021-09-11 22:18:44 +02:00
|
|
|
+ || !Double.isFinite(clickedLocation.x) || !Double.isFinite(clickedLocation.y) || !Double.isFinite(clickedLocation.z)
|
|
|
|
+ || isOutsideOfReach(clickedLocation.x, clickedLocation.y, clickedLocation.z)) {
|
2022-03-01 06:43:03 +01:00
|
|
|
+ return;
|
|
|
|
+ }
|
2022-02-12 14:20:33 +01:00
|
|
|
+ // Paper end
|
2022-03-01 06:43:03 +01:00
|
|
|
+
|
|
|
|
if (this.player.level.getServer() != null && this.player.chunkPosition().getChessboardDistance(new ChunkPos(blockposition)) < this.player.level.spigotConfig.viewDistance) { // Spigot
|
|
|
|
double d0 = 1.0000001D;
|
2022-02-12 14:20:33 +01:00
|
|
|
|