Don't mutate the position of Items for MC-4 Fix (#12702)

This commit is contained in:
Owen
2025-06-25 15:51:26 -04:00
committed by GitHub
parent 692e93a91f
commit ea10fa4a79
5 changed files with 19 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/network/protocol/game/VecDeltaCodec.java --- a/net/minecraft/network/protocol/game/VecDeltaCodec.java
+++ b/net/minecraft/network/protocol/game/VecDeltaCodec.java +++ b/net/minecraft/network/protocol/game/VecDeltaCodec.java
@@ -5,16 +_,16 @@ @@ -5,7 +_,7 @@
public class VecDeltaCodec { public class VecDeltaCodec {
private static final double TRUNCATION_STEPS = 4096.0; private static final double TRUNCATION_STEPS = 4096.0;
@@ -9,14 +9,3 @@
@VisibleForTesting @VisibleForTesting
static long encode(double value) { static long encode(double value) {
- return Math.round(value * 4096.0);
+ return Math.round(value * 4096.0); // Paper - Fix MC-4; diff on change
}
@VisibleForTesting
static double decode(long value) {
- return value / 4096.0;
+ return value / 4096.0; // Paper - Fix MC-4; diff on change
}
public Vec3 decode(long x, long y, long z) {

View File

@@ -1786,7 +1786,7 @@
} }
public void addDeltaMovement(Vec3 addend) { public void addDeltaMovement(Vec3 addend) {
@@ -3661,9 +_,45 @@ @@ -3661,9 +_,35 @@
return this.getZ((2.0 * this.random.nextDouble() - 1.0) * scale); return this.getZ((2.0 * this.random.nextDouble() - 1.0) * scale);
} }
@@ -1815,16 +1815,6 @@
+ return; + return;
+ } + }
+ // Paper end - Block invalid positions and bounding box + // 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 VecDeltaCodec todo computation changed?
+ x = Mth.lfloor(x * 4096.0) * (1 / 4096.0);
+ y = Mth.lfloor(y * 4096.0) * (1 / 4096.0);
+ z = Mth.lfloor(z * 4096.0) * (1 / 4096.0);
+ }
+ }
+ // Paper end - Fix MC-4
if (this.position.x != x || this.position.y != y || this.position.z != z) { if (this.position.x != x || this.position.y != y || this.position.z != z) {
+ synchronized (this.posLock) { // Paper - detailed watchdog information + synchronized (this.posLock) { // Paper - detailed watchdog information
this.position = new Vec3(x, y, z); this.position = new Vec3(x, y, z);

View File

@@ -24,6 +24,21 @@
} }
public ItemEntity(Level level, double posX, double posY, double posZ, ItemStack itemStack, double deltaX, double deltaY, double deltaZ) { public ItemEntity(Level level, double posX, double posY, double posZ, ItemStack itemStack, double deltaX, double deltaY, double deltaZ) {
@@ -79,6 +_,14 @@
this.bobOffs = other.bobOffs;
}
+ // Paper start - Require item entities to send their location precisely (Fixes MC-4)
+ {
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().misc.sendFullPosForItemEntities) {
+ this.setRequiresPrecisePosition(true);
+ }
+ }
+ // Paper end - Require item entities to send their location precisely (Fixes MC-4)
+
@Override
public boolean dampensVibrations() {
return this.getItem().is(ItemTags.DAMPENS_VIBRATIONS);
@@ -116,7 +_,7 @@ @@ -116,7 +_,7 @@
@Override @Override
public void tick() { public void tick() {

View File

@@ -343,7 +343,7 @@ public class GlobalConfiguration extends ConfigurationPart {
} }
} }
public int maxJoinsPerTick = 5; public int maxJoinsPerTick = 5;
public boolean fixEntityPositionDesync = true; public boolean sendFullPosForItemEntities = false;
public boolean loadPermissionsYmlBeforePlugins = true; public boolean loadPermissionsYmlBeforePlugins = true;
@Constraints.Min(4) @Constraints.Min(4)
public int regionFileCacheSize = 256; public int regionFileCacheSize = 256;

View File

@@ -82,6 +82,7 @@ interface RemovedConfigurations {
path("unsupported-settings", "allow-grindstone-overstacking"), path("unsupported-settings", "allow-grindstone-overstacking"),
path("unsupported-settings", "allow-tripwire-disarming-exploits"), path("unsupported-settings", "allow-tripwire-disarming-exploits"),
path("commands", "fix-target-selector-tag-completion"), path("commands", "fix-target-selector-tag-completion"),
path("misc", "fix-entity-position-desync")
}; };
} }