aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0257-Add-option-to-prevent-players-from-moving-into-unloa.patch
blob: 33cebcaddbc4697486906c4d268a724811bfed93 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
index 4f6985d4458cfba8fd8323d06363763871da2fa0..b15cd1b5b4e4e20a70099acd351e3ac1025a6f31 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -498,9 +498,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                 double d0 = entity.getX();
                 double d1 = entity.getY();
                 double d2 = entity.getZ();
-                double d3 = ServerGamePacketListenerImpl.clampHorizontal(packet.getX());
-                double d4 = ServerGamePacketListenerImpl.clampVertical(packet.getY());
-                double d5 = ServerGamePacketListenerImpl.clampHorizontal(packet.getZ());
+                double d3 = ServerGamePacketListenerImpl.clampHorizontal(packet.getX()); final double toX = d3; // Paper - OBFHELPER
+                double d4 = ServerGamePacketListenerImpl.clampVertical(packet.getY()); final double toY = d4; // Paper - OBFHELPER
+                double d5 = ServerGamePacketListenerImpl.clampHorizontal(packet.getZ()); final double toZ = d5; // Paper - OBFHELPER
                 float f = Mth.wrapDegrees(packet.getYRot());
                 float f1 = Mth.wrapDegrees(packet.getXRot());
                 double d6 = d3 - this.vehicleFirstGoodX;
@@ -534,6 +534,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                 }
                 speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
 
+                // Paper start - Prevent moving into unloaded chunks
+                if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (
+                    !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())))
+                    )) {
+                    this.connection.send(new ClientboundMoveVehiclePacket(entity));
+                    return;
+                }
+                // Paper end - Prevent moving into unloaded chunks
+
                 if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
                 // CraftBukkit end
                     ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
@@ -1167,9 +1177,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                 }
 
                 if (!this.updateAwaitingTeleport()) {
-                    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
+                    double d1 = ServerGamePacketListenerImpl.clampVertical(packet.getY(this.player.getY())); final double toY = d1; // Paper - OBFHELPER
+                    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()));
 
@@ -1227,6 +1237,12 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                                 } else {
                                     speed = this.player.getAbilities().walkingSpeed * 10f;
                                 }
+                                // 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())))) {
+                                    this.internalTeleport(PositionMoveRotation.of(this.player), Collections.emptySet());
+                                    return;
+                                }
+                                // Paper end - Prevent moving into unloaded chunks
 
                                 if (this.shouldCheckPlayerMovement(flag)) {
                                     float f2 = flag ? 300.0F : 100.0F;