Paper/patches/server/0525-MC-4-Fix-item-position-desync.patch

51 lines
2.4 KiB
Diff
Raw Normal View History

2022-06-11 10:41:59 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Tue, 8 Dec 2020 20:24:52 -0600
Subject: [PATCH] MC-4: Fix item position desync
This fixes item position desync (MC-4) by running the item coordinates
through the encode/decode methods of the packet that causes the precision
loss, which forces the server to lose the same precision as the client
keeping them in sync.
diff --git a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
2022-12-07 21:16:54 +01:00
index 5ca3ad7b3d7606accd0a58b3c708fadb349608f7..4b6e0fe2fabcc55007fd8979e81f66df9c0278b7 100644
2022-06-11 10:41:59 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
+++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
2022-12-07 21:16:54 +01:00
@@ -9,12 +9,12 @@ public class VecDeltaCodec {
2022-06-11 10:41:59 +02:00
2022-12-07 21:16:54 +01:00
@VisibleForTesting
static long encode(double value) {
- return Math.round(value * 4096.0D);
+ return Math.round(value * 4096.0D); // Paper - diff on change
2022-06-11 10:41:59 +02:00
}
2022-12-07 21:16:54 +01:00
@VisibleForTesting
static double decode(long value) {
2022-06-11 10:41:59 +02:00
- return (double)value / 4096.0D;
2022-12-07 21:16:54 +01:00
+ return (double)value / 4096.0D; // Paper - diff on change
2022-06-11 10:41:59 +02:00
}
public Vec3 decode(long x, long y, long z) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2022-12-23 20:59:11 +01:00
index d8dfd84a8e97e0e852362e1424e50c2f00fe6458..9833207c4d29a082cd68d52e72490e7a314f420c 100644
2022-06-11 10:41:59 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2022-12-23 20:59:11 +01:00
@@ -4029,6 +4029,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
return;
}
// Paper end - rewrite chunk system
2022-06-11 10:41:59 +02:00
+ // Paper start - fix MC-4
+ if (this instanceof ItemEntity) {
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().misc.fixEntityPositionDesync) {
2022-06-11 11:02:09 +02:00
+ // encode/decode from ClientboundMoveEntityPacket
2022-06-11 10:41:59 +02:00
+ x = Mth.lfloor(x * 4096.0D) * (1 / 4096.0D);
+ y = Mth.lfloor(y * 4096.0D) * (1 / 4096.0D);
+ z = Mth.lfloor(z * 4096.0D) * (1 / 4096.0D);
+ }
+ }
+ // Paper end - fix MC-4
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);