mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-28 11:29:11 +00:00
37 lines
1.5 KiB
Diff
37 lines
1.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Doc <nachito94@msn.com>
|
|
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/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
index a4ac34ebb58a404f4fca7e763e61d4ab05ee3af4..ed2cee2bd3ab7dcd05517889efcb658acb00b805 100644
|
|
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
@@ -103,6 +103,20 @@ public final class MCUtil {
|
|
run.run();
|
|
}
|
|
|
|
+ // Paper start - avoid setting NaN values
|
|
+ public static double sanitizeNanInf(final double value, final double defaultValue) {
|
|
+ return Double.isNaN(value) || Double.isInfinite(value) ? defaultValue : value;
|
|
+ }
|
|
+
|
|
+ public static Vec3 sanitizeNanInf(final Vec3 vec3, final double defaultValue) {
|
|
+ return new Vec3(
|
|
+ sanitizeNanInf(vec3.x, defaultValue),
|
|
+ sanitizeNanInf(vec3.y, defaultValue),
|
|
+ sanitizeNanInf(vec3.z, defaultValue)
|
|
+ );
|
|
+ }
|
|
+ // Paper end - avoid setting NaN values
|
|
+
|
|
public static <T> T ensureMain(Supplier<T> run) {
|
|
return ensureMain(null, run);
|
|
}
|