mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
976c6d425b
A recent commit has been made that caused patches to be out of order, rebuilding
85 lines
4.3 KiB
Diff
85 lines
4.3 KiB
Diff
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
|
|
index 652d87fc5d566dba8018c81676329f0e0bca471b..c56e7fb18f9a56c8025eb70a524f028b5942da37 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
@@ -474,4 +474,9 @@ public class PaperConfig {
|
|
private static void trackPluginScoreboards() {
|
|
trackPluginScoreboards = getBoolean("settings.track-plugin-scoreboards", false);
|
|
}
|
|
+
|
|
+ public static boolean fixEntityPositionDesync = true;
|
|
+ private static void fixEntityPositionDesync() {
|
|
+ fixEntityPositionDesync = getBoolean("settings.fix-entity-position-desync", fixEntityPositionDesync);
|
|
+ }
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutEntity.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutEntity.java
|
|
index e80429368afced0299d9f41b97251cd6c64b1759..0eed10a6c4e0c7245f219d19ed1e2e5c94364db9 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutEntity.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutEntity.java
|
|
@@ -19,11 +19,11 @@ public class PacketPlayOutEntity implements Packet<PacketListenerPlayOut> {
|
|
protected boolean i;
|
|
|
|
public static long a(double d0) {
|
|
- return MathHelper.d(d0 * 4096.0D);
|
|
+ return MathHelper.d(d0 * 4096.0D); // Paper - check EntityItem#setPositionRaw on update
|
|
}
|
|
|
|
public static Vec3D a(long i, long j, long k) {
|
|
- return (new Vec3D((double) i, (double) j, (double) k)).a(2.44140625E-4D);
|
|
+ return (new Vec3D((double) i, (double) j, (double) k)).a(2.44140625E-4D); // Paper - check EntityItem#setPositionRaw on update
|
|
}
|
|
|
|
public PacketPlayOutEntity() {}
|
|
diff --git a/src/main/java/net/minecraft/util/MathHelper.java b/src/main/java/net/minecraft/util/MathHelper.java
|
|
index caa628417bb9c1c65b037e4f3f762b08272c6d09..cc566784c7dd21cc2c44e0f351347f657e57ddcf 100644
|
|
--- a/src/main/java/net/minecraft/util/MathHelper.java
|
|
+++ b/src/main/java/net/minecraft/util/MathHelper.java
|
|
@@ -9,7 +9,7 @@ import net.minecraft.core.BaseBlockPosition;
|
|
public class MathHelper {
|
|
|
|
public static final float a = c(2.0F);
|
|
- private static final float[] b = (float[]) SystemUtils.a((Object) (new float[65536]), (afloat) -> {
|
|
+ private static final float[] b = (float[]) SystemUtils.a((new float[65536]), (afloat) -> { // Paper - decompile error
|
|
for (int i = 0; i < afloat.length; ++i) {
|
|
afloat[i] = (float) Math.sin((double) i * 3.141592653589793D * 2.0D / 65536.0D);
|
|
}
|
|
@@ -49,6 +49,7 @@ public class MathHelper {
|
|
return d0 < (double) i ? i - 1 : i;
|
|
}
|
|
|
|
+ public static long floorLong(double d0) { return d(d0); } // Paper - OBFHELPER
|
|
public static long d(double d0) {
|
|
long i = (long) d0;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityItem.java b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
index 11e029f6f97f1dd9c32e311d1a3800f2fa54b91f..575833807ff647f30d7c2b7abcd01701c7dec85b 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/EntityItem.java
|
|
@@ -550,4 +550,16 @@ public class EntityItem extends Entity {
|
|
public Packet<?> P() {
|
|
return new PacketPlayOutSpawnEntity(this);
|
|
}
|
|
+
|
|
+ // Paper start - fix MC-4
|
|
+ public void setPositionRaw(double x, double y, double z) {
|
|
+ if (com.destroystokyo.paper.PaperConfig.fixEntityPositionDesync) {
|
|
+ // encode/decode from PacketPlayOutEntity
|
|
+ x = MathHelper.floorLong(x * 4096.0D) * (1 / 4096.0D);
|
|
+ y = MathHelper.floorLong(y * 4096.0D) * (1 / 4096.0D);
|
|
+ z = MathHelper.floorLong(z * 4096.0D) * (1 / 4096.0D);
|
|
+ }
|
|
+ super.setPositionRaw(x, y, z);
|
|
+ }
|
|
+ // Paper end - fix MC-4
|
|
}
|