Skip to content

Commit

Permalink
New ticking system, fixes Replay mod issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureZhen committed Feb 25, 2022
1 parent 4fe2379 commit f43937a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<T extends IAnimatable> extends GeoModelProvider<T>
Expand Down Expand Up @@ -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<T> predicate;
Expand Down Expand Up @@ -156,9 +153,4 @@ public void setMolangQueries(IAnimatable animatable, double currentTick) {
}
}
}

@Override
public double getCurrentTick() {
return GlfwUtil.getTime() * 20;
}
}
19 changes: 19 additions & 0 deletions src/main/java/software/bernie/geckolib3/util/AnimationTicker.java
Original file line number Diff line number Diff line change
@@ -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++;
}
}

0 comments on commit f43937a

Please sign in to comment.