From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Doc Date: Sat, 12 Apr 2025 12:41:08 -0400 Subject: [PATCH] PaperPR: Fix save/load NaN Entity Motion Original license: GPLv3 Original project: https://github.com/PaperMC/Paper Paper pull request: https://github.com/PaperMC/Paper/pull/12269 Fix Paper#12262 using like the same logic than "pitch/yaw" for set to 0 when a value is NaN diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java index f114a8f5143799d72e36e0a535888c5fb25213e1..a81983182ee3e3b874ba83ddf9bbc6ea772a2997 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -2474,6 +2474,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess } // CraftBukkit end + this.setDeltaMovement(io.papermc.paper.util.MCUtil.sanitizeNanInf(this.deltaMovement, 0D)); // Paper - remove NaN values before usage in saving Vec3 deltaMovement = this.getDeltaMovement(); compound.put("Motion", this.newDoubleList(deltaMovement.x, deltaMovement.y, deltaMovement.z)); // CraftBukkit start - Checking for NaN pitch/yaw and resetting to zero @@ -2620,9 +2621,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess ListTag list = compound.getList("Pos", 6); ListTag list1 = compound.getList("Motion", 6); ListTag list2 = compound.getList("Rotation", 5); - double _double = list1.getDouble(0); - double _double1 = list1.getDouble(1); - double _double2 = list1.getDouble(2); + // Paper start - avoid setting NaN values + double _double = list1.getDouble(0); _double = io.papermc.paper.util.MCUtil.sanitizeNanInf(_double, 0D); + double _double1 = list1.getDouble(1); _double1 = io.papermc.paper.util.MCUtil.sanitizeNanInf(_double1, 0D); + double _double2 = list1.getDouble(2); _double2 = io.papermc.paper.util.MCUtil.sanitizeNanInf(_double2, 0D); + // Paper end - avoid setting NaN values this.setDeltaMovement( Math.abs(_double) > 10.0 ? 0.0 : _double, Math.abs(_double1) > 10.0 ? 0.0 : _double1, Math.abs(_double2) > 10.0 ? 0.0 : _double2 );