From f43937aacfe824401fbedba3c939f01e357c492d Mon Sep 17 00:00:00 2001 From: AzureZhen Date: Fri, 25 Feb 2022 00:19:14 -0500 Subject: [PATCH] New ticking system, fixes Replay mod issues. --- .../geckolib3/model/AnimatedGeoModel.java | 18 +++++------------- .../geckolib3/util/AnimationTicker.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 src/main/java/software/bernie/geckolib3/util/AnimationTicker.java diff --git a/src/main/java/software/bernie/geckolib3/model/AnimatedGeoModel.java b/src/main/java/software/bernie/geckolib3/model/AnimatedGeoModel.java index 6b59015ee..b46611993 100644 --- a/src/main/java/software/bernie/geckolib3/model/AnimatedGeoModel.java +++ b/src/main/java/software/bernie/geckolib3/model/AnimatedGeoModel.java @@ -5,7 +5,6 @@ import com.eliotlash.molang.MolangParser; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.util.GlfwUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.util.Identifier; @@ -25,6 +24,7 @@ import software.bernie.geckolib3.model.provider.GeoModelProvider; import software.bernie.geckolib3.model.provider.IAnimatableModelProvider; import software.bernie.geckolib3.resource.GeckoLibCache; +import software.bernie.geckolib3.util.AnimationTicker; import software.bernie.geckolib3.util.MolangUtils; public abstract class AnimatedGeoModel extends GeoModelProvider @@ -52,16 +52,13 @@ public void setLivingAnimations(T entity, Integer uniqueID, AnimationEvent custo // Each animation has it's own collection of animations (called the // EntityAnimationManager), which allows for multiple independent animations AnimationData manager = entity.getFactory().getOrCreateAnimationData(uniqueID); - if (manager.startTick == null) { - manager.startTick = getCurrentTick(); + + if (manager.ticker == null) { + manager.ticker = new AnimationTicker(manager); } if (!MinecraftClient.getInstance().isPaused() || manager.shouldPlayWhilePaused) { - manager.tick = (getCurrentTick() - manager.startTick); - double gameTick = manager.tick; - double deltaTicks = gameTick - lastGameTickTime; - seekTime += deltaTicks; - lastGameTickTime = gameTick; + seekTime = manager.tick + MinecraftClient.getInstance().getTickDelta(); } AnimationEvent predicate; @@ -156,9 +153,4 @@ public void setMolangQueries(IAnimatable animatable, double currentTick) { } } } - - @Override - public double getCurrentTick() { - return GlfwUtil.getTime() * 20; - } } \ No newline at end of file diff --git a/src/main/java/software/bernie/geckolib3/util/AnimationTicker.java b/src/main/java/software/bernie/geckolib3/util/AnimationTicker.java new file mode 100644 index 000000000..c0edba2cb --- /dev/null +++ b/src/main/java/software/bernie/geckolib3/util/AnimationTicker.java @@ -0,0 +1,19 @@ +package software.bernie.geckolib3.util; + +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.client.MinecraftClient; +import software.bernie.geckolib3.core.manager.AnimationData; + +public class AnimationTicker { + + private AnimationData manager; + + public AnimationTicker(AnimationData manager) { + this.manager = manager; + ClientTickEvents.START_CLIENT_TICK.register(this::onTick); + } + + private void onTick(MinecraftClient minecraftClient) { + manager.tick++; + } +}