Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0617-MC-4-Fix-item-position-desync.patch
Josh Roy b31089a929
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5325)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
d264e972 #591: Add option for a consumer before spawning an item
1c537fce #590: Add spawn and transform reasons for piglin zombification.

CraftBukkit Changes:
ee5006d1 #810: Add option for a consumer before spawning an item
f6a39d3c #809: Add spawn and transform reasons for piglin zombification.
0c24068a Organise imports

Spigot Changes:
bff52619 Organise imports
2021-03-08 15:12:31 -08:00

85 Zeilen
4.2 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/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
index 0e75d97254c73b2525380024b41a42f56d87b3a5..5dfb54e17fcfe6bd30e6b2a449944606e1a0ef17 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
@@ -524,4 +524,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
}
diff --git a/src/main/java/net/minecraft/server/MathHelper.java b/src/main/java/net/minecraft/server/MathHelper.java
index 1731a1bca5ad02fd8cd8701f49c10cb74ee6f503..2e7721a650c5a351b3584665bd236f92ef577761 100644
--- a/src/main/java/net/minecraft/server/MathHelper.java
+++ b/src/main/java/net/minecraft/server/MathHelper.java
@@ -7,7 +7,7 @@ import java.util.function.IntPredicate;
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);
}
@@ -47,6 +47,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/server/PacketPlayOutEntity.java b/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
index e5da2b19c1177ba7f88f0aaad9d810bb313ce67b..8e48407fd405ac4c3eece7762b8155c5d0f00fa0 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutEntity.java
@@ -15,11 +15,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() {}