|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: BillyGalbreath <blake.galbreath@gmail.com> |
| 3 | +Date: Tue, 8 Dec 2020 20:24:52 -0600 |
| 4 | +Subject: [PATCH] MC-4: Fix item position desync |
| 5 | + |
| 6 | +This fixes item position desync (MC-4) by running the item coordinates |
| 7 | +through the encode/decode methods of the packet that causes the precision |
| 8 | +loss, which forces the server to lose the same precision as the client |
| 9 | +keeping them in sync. |
| 10 | + |
| 11 | +diff --git a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java |
| 12 | +index 3768a71491ef7836b9739bdaec7a077c523dbacd..a57957ace1a72b3308487f180a366c3879eceb21 100644 |
| 13 | +--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java |
| 14 | ++++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java |
| 15 | +@@ -8,11 +8,11 @@ public class VecDeltaCodec { |
| 16 | + public Vec3 base = Vec3.ZERO; // Paper |
| 17 | + |
| 18 | + private static long encode(double value) { |
| 19 | +- return Mth.lfloor(value * 4096.0D); |
| 20 | ++ return Mth.lfloor(value * 4096.0D); // Paper - check ItemEntity#setPosRaw on update |
| 21 | + } |
| 22 | + |
| 23 | + private static double decode(long value) { |
| 24 | +- return (double)value / 4096.0D; |
| 25 | ++ return (double)value / 4096.0D; // Paper - check ItemEntity#setPosRaw on update |
| 26 | + } |
| 27 | + |
| 28 | + public Vec3 decode(long x, long y, long z) { |
| 29 | +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java |
| 30 | +index 6b49e66f0e45eb7ed525fe4314d2a9615212f7e4..4f9a5837d66c1940385e94f80d865cde1c4cf2a2 100644 |
| 31 | +--- a/src/main/java/net/minecraft/world/entity/Entity.java |
| 32 | ++++ b/src/main/java/net/minecraft/world/entity/Entity.java |
| 33 | +@@ -3888,6 +3888,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { |
| 34 | + } |
| 35 | + public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) { |
| 36 | + // Paper end |
| 37 | ++ // Paper start - fix MC-4 |
| 38 | ++ if (this instanceof ItemEntity) { |
| 39 | ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().misc.fixEntityPositionDesync) { |
| 40 | ++ // encode/decode from PacketPlayOutEntity |
| 41 | ++ x = Mth.lfloor(x * 4096.0D) * (1 / 4096.0D); |
| 42 | ++ y = Mth.lfloor(y * 4096.0D) * (1 / 4096.0D); |
| 43 | ++ z = Mth.lfloor(z * 4096.0D) * (1 / 4096.0D); |
| 44 | ++ } |
| 45 | ++ } |
| 46 | ++ // Paper end - fix MC-4 |
| 47 | + if (this.position.x != x || this.position.y != y || this.position.z != z) { |
| 48 | + this.position = new Vec3(x, y, z); |
| 49 | + int i = Mth.floor(x); |
0 commit comments