2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Gabriele C <sgdc3.mail@gmail.com>
Date: Mon, 22 Oct 2018 17:34:10 +0200
Subject: [PATCH] Add option to prevent players from moving into unloaded
chunks #1551
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-12-03 19:21:12 +01:00
index 5f3d7ea96d690b68897d9092c624c77e49822af4..a87ea0f22b44c2fb67fd51bc8c9b0067aacac7de 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
2024-12-03 19:05:31 +01:00
@@ -500,9 +500,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2022-03-14 20:28:02 +01:00
double d0 = entity.getX();
double d1 = entity.getY();
double d2 = entity.getZ();
2024-12-03 19:05:31 +01:00
- double d3 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().x());
- double d4 = ServerGamePacketListenerImpl.clampVertical(packet.position().y());
- double d5 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().z());
+ double d3 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().x()); final double toX = d3; // Paper - OBFHELPER
+ double d4 = ServerGamePacketListenerImpl.clampVertical(packet.position().y()); final double toY = d4; // Paper - OBFHELPER
+ double d5 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().z()); final double toZ = d5; // Paper - OBFHELPER
float f = Mth.wrapDegrees(packet.yRot());
float f1 = Mth.wrapDegrees(packet.xRot());
2022-03-14 20:28:02 +01:00
double d6 = d3 - this.vehicleFirstGoodX;
2024-12-03 19:05:31 +01:00
@@ -536,6 +536,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
}
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
+ // Paper start - Prevent moving into unloaded chunks
2023-06-08 00:12:41 +02:00
+ if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (
2022-03-14 20:28:02 +01:00
+ !worldserver.areChunksLoadedForMove(this.player.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(this.player.position()))) ||
+ !worldserver.areChunksLoadedForMove(entity.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(entity.position())))
+ )) {
2021-06-11 14:02:28 +02:00
+ this.connection.send(new ClientboundMoveVehiclePacket(entity));
+ return;
+ }
2024-01-21 13:56:22 +01:00
+ // Paper end - Prevent moving into unloaded chunks
2021-06-11 14:02:28 +02:00
+
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
// CraftBukkit end
2022-03-01 06:43:03 +01:00
ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
2024-12-03 19:05:31 +01:00
@@ -1228,9 +1238,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2024-06-13 21:04:27 +02:00
}
2023-12-28 21:47:57 +01:00
2024-12-03 19:05:31 +01:00
if (!this.updateAwaitingTeleport() && this.player.hasClientLoaded()) {
2022-03-14 20:28:02 +01:00
- double d0 = ServerGamePacketListenerImpl.clampHorizontal(packet.getX(this.player.getX()));
- double d1 = ServerGamePacketListenerImpl.clampVertical(packet.getY(this.player.getY()));
- double d2 = ServerGamePacketListenerImpl.clampHorizontal(packet.getZ(this.player.getZ()));
+ double d0 = ServerGamePacketListenerImpl.clampHorizontal(packet.getX(this.player.getX())); final double toX = d0; // Paper - OBFHELPER
2024-01-26 19:41:41 +01:00
+ double d1 = ServerGamePacketListenerImpl.clampVertical(packet.getY(this.player.getY())); final double toY = d1; // Paper - OBFHELPER
2022-03-14 20:28:02 +01:00
+ double d2 = ServerGamePacketListenerImpl.clampHorizontal(packet.getZ(this.player.getZ())); final double toZ = d2; // Paper - OBFHELPER
float f = Mth.wrapDegrees(packet.getYRot(this.player.getYRot()));
float f1 = Mth.wrapDegrees(packet.getXRot(this.player.getXRot()));
2024-12-03 19:05:31 +01:00
@@ -1288,6 +1298,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-12-05 23:21:44 +01:00
} else {
speed = this.player.getAbilities().walkingSpeed * 10f;
}
2023-12-06 18:47:45 +01:00
+ // Paper start - Prevent moving into unloaded chunks
+ if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && !worldserver.areChunksLoadedForMove(this.player.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(this.player.position())))) {
2024-10-23 14:12:17 +02:00
+ this.internalTeleport(PositionMoveRotation.of(this.player), Collections.emptySet());
2023-12-06 18:47:45 +01:00
+ return;
+ }
2024-01-21 13:56:22 +01:00
+ // Paper end - Prevent moving into unloaded chunks
2021-06-11 14:02:28 +02:00
2024-10-23 14:12:17 +02:00
if (this.shouldCheckPlayerMovement(flag)) {
2024-04-24 07:43:09 +02:00
float f2 = flag ? 300.0F : 100.0F;