From 55cd639124e305251eb610586a55e4163ea288f6 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 2 Apr 2024 18:16:46 -0500 Subject: [PATCH] Separated client and server ticks into two static variables --- src/main/java/noppes/npcs/CommonProxy.java | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index 544467cc9..5bfd6b54f 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -1,6 +1,5 @@ package noppes.npcs; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -30,7 +29,8 @@ public class CommonProxy implements IGuiHandler { public final static HashSet clientPlayingAnimations = new HashSet<>(); public final static HashSet serverPlayingAnimations = new HashSet<>(); protected MillisTimer animationTimer = new MillisTimer(1000); - protected long totalTicks; + protected static long totalServerTicks; + protected static long totalClientTicks; public void load() { this.createAnimationThread(); @@ -48,11 +48,25 @@ public class CommonProxy implements IGuiHandler { } for (int i = 0; i < animationTimer.elapsedTicks; ++i) { - updateAnimations(clientPlayingAnimations); - updateAnimations(serverPlayingAnimations); - totalTicks++; + for (Animation animation : clientPlayingAnimations) { + int tickDuration = animation.currentFrame().tickDuration(); + if (updateAnimation(animation) && totalClientTicks % tickDuration == 0) { + animation.increaseTime(); + } + } + totalClientTicks++; + + for (Animation animation : serverPlayingAnimations) { + int tickDuration = animation.currentFrame().tickDuration(); + if (updateAnimation(animation) && totalServerTicks % tickDuration == 0) { + animation.increaseTime(); + } + } + totalServerTicks++; } - totalTicks %= 60 * 60 * 1000; + + totalClientTicks %= Long.MAX_VALUE; + totalServerTicks %= Long.MAX_VALUE; synchronized (clientPlayingAnimations) { clientPlayingAnimations.removeIf(CommonProxy.this::removeAnimation); @@ -69,15 +83,10 @@ public class CommonProxy implements IGuiHandler { thread.start(); } - private void updateAnimations(HashSet playingAnimations) { - for (Animation animation : playingAnimations) { - int tickDuration = animation.currentFrame().tickDuration(); - if ((animation.parent.isActive() - || animation.parent.animation == null && animation.parent.isActive(animation.parent.currentClientAnimation)) - && totalTicks % tickDuration == 0) { - animation.increaseTime(); - } - } + private boolean updateAnimation(Animation animation) { + return animation.parent.isActive() + || animation.parent.animation == null + && animation.parent.isActive(animation.parent.currentClientAnimation); } private boolean removeAnimation(Animation animation) {