From 0e3f46c74b8cd6bf629603327813b7a1f69ac445 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Mon, 29 Jan 2018 07:19:16 +0000 Subject: [PATCH] Use relative time offset, rather than absolute value, for animations (#4635) --- .../client/model/animation/Animation.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraftforge/client/model/animation/Animation.java b/src/main/java/net/minecraftforge/client/model/animation/Animation.java index 958f19c956..623f05b0d1 100644 --- a/src/main/java/net/minecraftforge/client/model/animation/Animation.java +++ b/src/main/java/net/minecraftforge/client/model/animation/Animation.java @@ -21,12 +21,17 @@ package net.minecraftforge.client.model.animation; import net.minecraft.world.World; +import java.lang.ref.WeakReference; + public enum Animation { INSTANCE; private float clientPartialTickTime; + private static long epochTime; + private static WeakReference worldRef; + /** * Get the global world time for the current tick, in seconds. */ @@ -40,7 +45,12 @@ public enum Animation */ public static float getWorldTime(World world, float tickProgress) { - return (world.getTotalWorldTime() + tickProgress) / 20; + if (worldRef == null || worldRef.get() != world) + { + epochTime = world.getTotalWorldTime(); + worldRef = new WeakReference<>(world); + } + return (world.getTotalWorldTime() - epochTime + tickProgress) / 20; } /**