mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Merge branch '1.20.1' into 1.20.2
# Conflicts: # gradle.properties
This commit is contained in:
commit
1c88d47e7b
1 changed files with 21 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
package com.minelittlepony.unicopia.util;
|
package com.minelittlepony.unicopia.util;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
|
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
@ -23,14 +25,30 @@ public class Lerp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean update(float newTarget, long changeDuration) {
|
public boolean update(float newTarget, long changeDuration) {
|
||||||
|
if (Float.isNaN(newTarget) || Float.isInfinite(newTarget)) {
|
||||||
|
Unicopia.LOGGER.error("Invalid lerp target. Target cannot be NaN or Infinity");
|
||||||
|
}
|
||||||
if (MathHelper.approximatelyEquals(end, newTarget)) {
|
if (MathHelper.approximatelyEquals(end, newTarget)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (changeDuration == 0) {
|
||||||
|
start = newTarget;
|
||||||
|
end = newTarget;
|
||||||
|
finished = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
start = getValue();
|
start = getValue();
|
||||||
startTime = Util.getMeasuringTimeMs();
|
startTime = Util.getMeasuringTimeMs();
|
||||||
end = newTarget;
|
end = newTarget;
|
||||||
duration = changeDuration;
|
duration = changeDuration;
|
||||||
finished = false;
|
finished = false;
|
||||||
|
if (Float.isNaN(start) || Float.isInfinite(start)) {
|
||||||
|
Unicopia.LOGGER.error("Invalid lerp start. Value cannot be NaN or Infinity");
|
||||||
|
}
|
||||||
|
if (Float.isNaN(end) || Float.isInfinite(end)) {
|
||||||
|
Unicopia.LOGGER.error("Invalid lerp end. Value cannot be NaN or Infinity");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +73,9 @@ public class Lerp {
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getDelta() {
|
private float getDelta() {
|
||||||
|
if (duration == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1);
|
return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue