From 186cf8842e84663ea564c9d04c0e97ea0d964bca Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 15 Jul 2021 20:01:48 -0700 Subject: [PATCH] Fix distanceSq check on block breaking (#6195) --- patches/server/Add-PlayerKickEvent-causes.patch | 2 +- .../server/Don-t-allow-digging-into-unloaded-chunks.patch | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/patches/server/Add-PlayerKickEvent-causes.patch b/patches/server/Add-PlayerKickEvent-causes.patch index 4d855ee296..47cf5ab55f 100644 --- a/patches/server/Add-PlayerKickEvent-causes.patch +++ b/patches/server/Add-PlayerKickEvent-causes.patch @@ -210,7 +210,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser - double blockDistanceSquared = this.player.distanceToSqr(blockposition.getX() + 0.5D, blockposition.getY() + 0.5D + 1.5D, blockposition.getZ() + 0.5D); // Copied from ServerPlayerGameMode#handleBlockBreakAction + double blockDistanceSquared = d0 * d0 + d1 * d1 + d2 * d2; if (blockDistanceSquared > 40 * 40) { LOGGER.warn("{} tried to break a block {} square blocks away from their position", this.player.getScoreboardName(), blockDistanceSquared); - this.disconnect("Invalid block break distance"); diff --git a/patches/server/Don-t-allow-digging-into-unloaded-chunks.patch b/patches/server/Don-t-allow-digging-into-unloaded-chunks.patch index 27d585d19f..01265393a1 100644 --- a/patches/server/Don-t-allow-digging-into-unloaded-chunks.patch +++ b/patches/server/Don-t-allow-digging-into-unloaded-chunks.patch @@ -72,7 +72,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 case STOP_DESTROY_BLOCK: - this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packet.getDirection(), this.player.level.getMaxBuildHeight()); + // Paper start - Don't allow digging in unloaded chunks -+ double blockDistanceSquared = this.player.distanceToSqr(blockposition.getX() + 0.5D, blockposition.getY() + 0.5D + 1.5D, blockposition.getZ() + 0.5D); // Copied from ServerPlayerGameMode#handleBlockBreakAction ++ // Copied from ServerPlayerGameMode#handleBlockBreakAction ++ double d0 = this.player.getX() - ((double) blockposition.getX() + 0.5D); ++ double d1 = this.player.getY() - ((double) blockposition.getY() + 0.5D) + 1.5D; ++ double d2 = this.player.getZ() - ((double) blockposition.getZ() + 0.5D); ++ double blockDistanceSquared = d0 * d0 + d1 * d1 + d2 * d2; + if (blockDistanceSquared > 40 * 40) { + LOGGER.warn("{} tried to break a block {} square blocks away from their position", this.player.getScoreboardName(), blockDistanceSquared); + this.disconnect("Invalid block break distance");