2021-06-14 20:50:22 +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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2022-03-01 04:25:13 +01:00
|
|
|
index 4c2d11d04b63d0e5e2eeb3743a1f79fea301c5aa..c75005b934271e4b8864d949052d56465571f011 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2021-11-24 18:22:48 +01:00
|
|
|
@@ -101,6 +101,11 @@ public class PaperConfig {
|
2021-06-14 20:50:22 +02:00
|
|
|
trackPluginScoreboards = getBoolean("settings.track-plugin-scoreboards", false);
|
|
|
|
}
|
2021-11-24 18:22:48 +01:00
|
|
|
|
2021-06-14 20:50:22 +02:00
|
|
|
+ public static boolean fixEntityPositionDesync = true;
|
|
|
|
+ private static void fixEntityPositionDesync() {
|
|
|
|
+ fixEntityPositionDesync = getBoolean("settings.fix-entity-position-desync", fixEntityPositionDesync);
|
|
|
|
+ }
|
2021-11-24 18:22:48 +01:00
|
|
|
+
|
|
|
|
public static void registerCommands() {
|
|
|
|
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
|
|
|
MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Paper", entry.getValue());
|
2021-06-14 20:50:22 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
|
|
|
|
index b30c08bfb8c55161543a4ef09f2e462e0a1fe4ae..ec93f5300cc7d423ec0d292f0f8443f900d72dab 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundMoveEntityPacket.java
|
|
|
|
@@ -21,11 +21,11 @@ public abstract class ClientboundMoveEntityPacket implements Packet<ClientGamePa
|
|
|
|
protected final boolean hasPos;
|
|
|
|
|
|
|
|
public static long entityToPacket(double coord) {
|
|
|
|
- return Mth.lfloor(coord * 4096.0D);
|
|
|
|
+ return Mth.lfloor(coord * 4096.0D); // Paper - check ItemEntity#setPosRaw on update
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double packetToEntity(long coord) {
|
|
|
|
- return (double)coord / 4096.0D;
|
|
|
|
+ return (double)coord / 4096.0D; // Paper - check ItemEntity#setPosRaw on update
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vec3 updateEntityPosition(Vec3 orig) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
2022-03-01 04:25:13 +01:00
|
|
|
index 1e3436849760430b0db303e716f50555046d6f3e..86a9cbc0768575138c09217cd300c2d9d08540fc 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -3828,6 +3828,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
2021-07-09 03:18:32 +02:00
|
|
|
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
|
|
|
|
// Paper end
|
2021-06-14 20:50:22 +02:00
|
|
|
+ // Paper start - fix MC-4
|
|
|
|
+ if (this instanceof ItemEntity) {
|
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.fixEntityPositionDesync) {
|
|
|
|
+ // encode/decode from PacketPlayOutEntity
|
|
|
|
+ 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
|
2021-07-09 03:18:32 +02:00
|
|
|
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);
|