aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0510-Fix-for-large-move-vectors-crashing-server.patch
blob: ce662351debccc412b17c3a9f608901abe64677c (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
Date: Sun, 17 May 2020 23:47:33 -0700
Subject: [PATCH] Fix for large move vectors crashing server

Check movement distance also based on current position.

diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index b7f876a00abdedcf6822b7dae61144e7fd94fdb3..def6838c09a859e5b3297b8251432f921720235e 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -508,20 +508,31 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
 
             if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
                 ServerLevel worldserver = this.player.getLevel();
-                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 d0 = entity.getX();final double fromX = d0; // Paper - OBFHELPER
+                double d1 = entity.getY();final double fromY = d1; // Paper - OBFHELPER
+                double d2 = entity.getZ();final double fromZ = d2; // Paper - OBFHELPER
+                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;
                 double d7 = d4 - this.vehicleFirstGoodY;
                 double d8 = d5 - this.vehicleFirstGoodZ;
                 double d9 = entity.getDeltaMovement().lengthSqr();
-                double d10 = d6 * d6 + d7 * d7 + d8 * d8;
-
+                // Paper start - fix large move vectors killing the server
+                double currDeltaX = toX - fromX;
+                double currDeltaY = toY - fromY;
+                double currDeltaZ = toZ - fromZ;
+                double d10 = Math.max(d6 * d6 + d7 * d7 + d8 * d8, (currDeltaX * currDeltaX + currDeltaY * currDeltaY + currDeltaZ * currDeltaZ) - 1);
+                // Paper end - fix large move vectors killing the server
+
+                // Paper start - fix large move vectors killing the server
+                double otherFieldX = d3 - this.vehicleLastGoodX;
+                double otherFieldY = d4 - this.vehicleLastGoodY - 1.0E-6D;
+                double otherFieldZ = d5 - this.vehicleLastGoodZ;
+                d10 = Math.max(d10, (otherFieldX * otherFieldX + otherFieldY * otherFieldY + otherFieldZ * otherFieldZ) - 1);
+                // Paper end - fix large move vectors killing the server
 
                 // CraftBukkit start - handle custom speeds and skipped ticks
                 this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
@@ -564,9 +575,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
 
                 boolean flag = worldserver.noCollision(entity, entity.getBoundingBox().deflate(0.0625D));
 
-                d6 = d3 - this.vehicleLastGoodX;
-                d7 = d4 - this.vehicleLastGoodY - 1.0E-6D;
-                d8 = d5 - this.vehicleLastGoodZ;
+                d6 = d3 - this.vehicleLastGoodX; // Paper - diff on change, used for checking large move vectors above
+                d7 = d4 - this.vehicleLastGoodY - 1.0E-6D; // Paper - diff on change, used for checking large move vectors above
+                d8 = d5 - this.vehicleLastGoodZ; // Paper - diff on change, used for checking large move vectors above
                 boolean flag1 = entity.verticalCollisionBelow;
 
                 entity.move(MoverType.PLAYER, new Vec3(d6, d7, d8));
@@ -1242,14 +1253,25 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
                         float prevPitch = this.player.getXRot();
                         // CraftBukkit end
                         double d3 = this.player.getX(); final double toX = d3; // Paper - OBFHELPER
-                        double d4 = this.player.getY();
+                        double d4 = this.player.getY(); final double toY = d4; // Paper - OBFHELPER
                         double d5 = this.player.getZ(); final double toZ = d5; // Paper - OBFHELPER
                         double d6 = this.player.getY();
                         double d7 = d0 - this.firstGoodX;
                         double d8 = d1 - this.firstGoodY;
                         double d9 = d2 - this.firstGoodZ;
                         double d10 = this.player.getDeltaMovement().lengthSqr();
-                        double d11 = d7 * d7 + d8 * d8 + d9 * d9;
+                        // Paper start - fix large move vectors killing the server
+                        double currDeltaX = toX - prevX;
+                        double currDeltaY = toY - prevY;
+                        double currDeltaZ = toZ - prevZ;
+                        double d11 = Math.max(d7 * d7 + d8 * d8 + d9 * d9, (currDeltaX * currDeltaX + currDeltaY * currDeltaY + currDeltaZ * currDeltaZ) - 1);
+                        // Paper end - fix large move vectors killing the server
+                        // Paper start - fix large move vectors killing the server
+                        double otherFieldX = d0 - this.lastGoodX;
+                        double otherFieldY = d1 - this.lastGoodY;
+                        double otherFieldZ = d2 - this.lastGoodZ;
+                        d11 = Math.max(d11, (otherFieldX * otherFieldX + otherFieldY * otherFieldY + otherFieldZ * otherFieldZ) - 1);
+                        // Paper end - fix large move vectors killing the server
 
                         if (this.player.isSleeping()) {
                             if (d11 > 1.0D) {
@@ -1301,9 +1323,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
 
                             AABB axisalignedbb = this.player.getBoundingBox();
 
-                            d7 = d0 - this.lastGoodX;
-                            d8 = d1 - this.lastGoodY;
-                            d9 = d2 - this.lastGoodZ;
+                            d7 = d0 - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
+                            d8 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
+                            d9 = d2 - this.lastGoodZ; // Paper - diff on change, used for checking large move vectors above
                             boolean flag = d8 > 0.0D;
 
                             if (this.player.isOnGround() && !packet.isOnGround() && flag) {