From 0ba987159fece58133f5015dcd4b6de6afc56fa6 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 24 Feb 2024 16:22:41 +0000 Subject: [PATCH] Prevent delta from becoming infinity or nan when duration is 0 --- .../java/com/minelittlepony/unicopia/util/Lerp.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/minelittlepony/unicopia/util/Lerp.java b/src/main/java/com/minelittlepony/unicopia/util/Lerp.java index 4ce60ff4..2032209c 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/Lerp.java +++ b/src/main/java/com/minelittlepony/unicopia/util/Lerp.java @@ -31,6 +31,13 @@ public class Lerp { if (MathHelper.approximatelyEquals(end, newTarget)) { return false; } + if (changeDuration == 0) { + start = newTarget; + end = newTarget; + finished = true; + return false; + } + start = getValue(); startTime = Util.getMeasuringTimeMs(); end = newTarget; @@ -66,6 +73,9 @@ public class Lerp { } private float getDelta() { + if (duration == 0) { + return 1; + } return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1); } }