Fix save/load NaN Entity Motion (#12269)

This commit is contained in:
Pedro
2025-04-30 13:53:32 -04:00
committed by GitHub
parent cd4fe5b7d0
commit 5acfdd6af4
3 changed files with 31 additions and 11 deletions

View File

@ -694,7 +694,7 @@
return true;
}
}
@@ -1805,14 +_,34 @@
@@ -1805,14 +_,35 @@
}
public CompoundTag saveWithoutId(CompoundTag compound) {
@ -715,6 +715,7 @@
}
+ } // CraftBukkit
+ this.setDeltaMovement(io.papermc.paper.util.MCUtil.sanitizeNanInf(this.deltaMovement, 0D)); // Paper - remove NaN values before usage in saving
compound.store("Motion", Vec3.CODEC, this.getDeltaMovement());
+ // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero
+ // TODO: make sure this is the best way to address this.
@ -810,6 +811,15 @@
return compound;
} catch (Throwable var8) {
CrashReport crashReport = CrashReport.forThrowable(var8, "Saving entity NBT");
@@ -1888,7 +_,7 @@
public void load(CompoundTag compound) {
try {
Vec3 vec3 = compound.read("Pos", Vec3.CODEC).orElse(Vec3.ZERO);
- Vec3 vec31 = compound.read("Motion", Vec3.CODEC).orElse(Vec3.ZERO);
+ Vec3 vec31 = compound.read("Motion", Vec3.CODEC).orElse(Vec3.ZERO); vec31 = io.papermc.paper.util.MCUtil.sanitizeNanInf(vec31, 0D); // Paper - avoid setting NaN values
Vec2 vec2 = compound.read("Rotation", Vec2.CODEC).orElse(Vec2.ZERO);
this.setDeltaMovement(Math.abs(vec31.x) > 10.0 ? 0.0 : vec31.x, Math.abs(vec31.y) > 10.0 ? 0.0 : vec31.y, Math.abs(vec31.z) > 10.0 ? 0.0 : vec31.z);
this.hasImpulse = true;
@@ -1932,6 +_,67 @@
} else {
throw new IllegalStateException("Entity has invalid rotation");