mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 11:42:55 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
86 lines
6 KiB
Diff
86 lines
6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
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 82f49aad1d0ce2d62bf61aa634ebef3711d4d930..d33cf08f7c47111823abbce481505946db249577 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -492,9 +492,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
float prevYaw = this.player.getYRot();
|
|
float prevPitch = this.player.getXRot();
|
|
// CraftBukkit end
|
|
- double d0 = entity.getX();
|
|
- double d1 = entity.getY();
|
|
- double d2 = entity.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
|
|
@@ -504,7 +504,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
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);
|
|
+ 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;
|
|
@@ -550,9 +559,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
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;
|
|
|
|
if (entity instanceof LivingEntity) {
|
|
@@ -1253,7 +1262,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
double d7 = d1 - this.firstGoodY;
|
|
double d8 = d2 - this.firstGoodZ;
|
|
double d9 = this.player.getDeltaMovement().lengthSqr();
|
|
- double d10 = d6 * d6 + d7 * d7 + d8 * d8;
|
|
+ // Paper start - fix large move vectors killing the server
|
|
+ double currDeltaX = toX - prevX;
|
|
+ double currDeltaY = toY - prevY;
|
|
+ double currDeltaZ = toZ - prevZ;
|
|
+ double d10 = Math.max(d6 * d6 + d7 * d7 + d8 * d8, (currDeltaX * currDeltaX + currDeltaY * currDeltaY + currDeltaZ * currDeltaZ) - 1);
|
|
+ double otherFieldX = d0 - this.lastGoodX;
|
|
+ double otherFieldY = d1 - this.lastGoodY;
|
|
+ double otherFieldZ = d2 - this.lastGoodZ;
|
|
+ d10 = Math.max(d10, (otherFieldX * otherFieldX + otherFieldY * otherFieldY + otherFieldZ * otherFieldZ) - 1);
|
|
+ // Paper end - fix large move vectors killing the server
|
|
|
|
if (this.player.isSleeping()) {
|
|
if (d10 > 1.0D) {
|
|
@@ -1309,9 +1327,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
AABB axisalignedbb = this.player.getBoundingBox();
|
|
|
|
- d6 = d0 - this.lastGoodX;
|
|
- d7 = d1 - this.lastGoodY;
|
|
- d8 = d2 - this.lastGoodZ;
|
|
+ d6 = d0 - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
|
|
+ d7 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
|
|
+ d8 = d2 - this.lastGoodZ; // Paper - diff on change, used for checking large move vectors above
|
|
boolean flag1 = d7 > 0.0D;
|
|
|
|
if (this.player.onGround() && !packet.isOnGround() && flag1) {
|