Made animation threading compatible on the client & server side

This commit is contained in:
Luis C.M committed 2024-03-24 03:14:11 -05:00
1 parent cf4e5f22b1
commit 16c3395d8c
6 files changed
+176 -48

No files matched your search

@@ -1,6 +1,7 @@
package noppes.npcs.client;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.CommonProxy;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.ImageData;
@@ -21,7 +22,6 @@ public class ClientCacheHandler {
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
public static HashSet<Animation> playingAnimations = new HashSet<>();
public static Party party;
@@ -57,7 +57,7 @@ public class ClientCacheHandler {
ClientCacheHandler.skinOverlays.clear();
ClientCacheHandler.playerAnimations.clear();
ClientCacheHandler.playerData.animationData.clearCache();
ClientCacheHandler.playingAnimations.clear();
CommonProxy.clientPlayingAnimations.clear();
}
public static void clearSkinCache() {
@@ -23,7 +23,6 @@ import net.minecraft.stats.Achievement;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Timer;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
@@ -60,7 +59,6 @@ import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.StringCache;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.entity.data.ModelData;
@@ -82,33 +80,8 @@ public class ClientProxy extends CommonProxy {
public static FontContainer Font;
private static Timer animationTimer = new Timer(1000);
private static long totalTicks;
public void load() {
Thread thread = (new Thread("Animation Thread") { public void run() {
while (true) {
if (!Minecraft.getMinecraft().isGamePaused()) {
animationTimer.updateTimer();
}
try {
for (int i = 0; i < animationTimer.elapsedTicks; ++i) {
for (Animation animation : ClientCacheHandler.playingAnimations) {
if (animation.parent.isActive() && totalTicks % animation.currentFrame().tickDuration() == 0) {
animation.increaseTime();
}
}
totalTicks++;
}
totalTicks %= 60 * 60 * 1000;
ClientCacheHandler.playingAnimations.removeIf(animation ->
animation.parent.animation != animation || !animation.parent.isActive());
} catch (Exception ignored) {}
}
}});
thread.setDaemon(true);
thread.start();
this.createAnimationThread();
Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
createFolders();