aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0472-MC-4-Fix-item-position-desync.patch
blob: f1fa7d66d3e1c1d8821bb33a518088460366795f (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
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
index 05ac41e136da43284fb24a6b698ebd36318278fb..3c4ac79c094dc2fff7de94150a34b7bf814ac0de 100644
--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
+++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
@@ -9,12 +9,12 @@ public class VecDeltaCodec {
 
     @VisibleForTesting
     static long encode(double value) {
-        return Math.round(value * 4096.0D);
+        return Math.round(value * 4096.0D); // Paper - Fix MC-4; diff on change
     }
 
     @VisibleForTesting
     static double decode(long value) {
-        return (double)value / 4096.0D;
+        return (double)value / 4096.0D; // Paper - Fix MC-4; diff on change
     }
 
     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
index 3b9c691973f11b7d4db8fb77d2b02aa0d07ed7b5..df389ebaaef8ef307adb6c604ce22a192a522ba4 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4186,6 +4186,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
             return;
         }
         // Paper end - Block invalid positions and bounding box
+        // Paper start - Fix MC-4
+        if (this instanceof ItemEntity) {
+            if (io.papermc.paper.configuration.GlobalConfiguration.get().misc.fixEntityPositionDesync) {
+                // encode/decode from ClientboundMoveEntityPacket
+                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);