From 3f79c79a85eff75fcba5149aeae94ab586b26b2a Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:51:08 -0700 Subject: [PATCH] fix(fabric): Use shutdown hook instead of client stopping event for shutdown, as on NeoForge fixes #199 --- .../xyz/jpenilla/tabtps/fabric/TabTPSFabricClient.java | 7 ++++--- .../xyz/jpenilla/tabtps/neoforge/TabTPSNeoForgeClient.java | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/TabTPSFabricClient.java b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/TabTPSFabricClient.java index f701df22..5cee29b7 100644 --- a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/TabTPSFabricClient.java +++ b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/TabTPSFabricClient.java @@ -24,15 +24,16 @@ package xyz.jpenilla.tabtps.fabric; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import xyz.jpenilla.tabtps.common.TabTPS; -public class TabTPSFabricClient implements ClientModInitializer { +public final class TabTPSFabricClient implements ClientModInitializer { @Override public void onInitializeClient() { - ClientLifecycleEvents.CLIENT_STOPPING.register(minecraft -> { + final Thread thread = new Thread(() -> { final TabTPS tabTPS = TabTPSFabric.get().tabTPS(); tabTPS.shutdown(); }); + thread.setName("TabTPS-Client-Shutdown-Thread"); + Runtime.getRuntime().addShutdownHook(thread); } } diff --git a/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/TabTPSNeoForgeClient.java b/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/TabTPSNeoForgeClient.java index 9e807234..9041bea7 100644 --- a/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/TabTPSNeoForgeClient.java +++ b/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/TabTPSNeoForgeClient.java @@ -30,9 +30,11 @@ @Mod(value = "tabtps", dist = Dist.CLIENT) public final class TabTPSNeoForgeClient { public TabTPSNeoForgeClient() { - Runtime.getRuntime().addShutdownHook(new Thread(() -> { + final Thread thread = new Thread(() -> { final TabTPS tabTPS = TabTPSNeoForge.get().tabTPS(); tabTPS.shutdown(); - })); + }); + thread.setName("TabTPS-Client-Shutdown-Thread"); + Runtime.getRuntime().addShutdownHook(thread); } }