diff --git a/gradle.properties b/gradle.properties index 8235d74..6ef9218 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ mod_name=3944Realms 's Lib Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=0.0.13 +mod_version=0.0.14 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/top/r3944realms/lib39/core/event/CommonHandler.java b/src/main/java/top/r3944realms/lib39/core/event/CommonHandler.java index 6e2d973..ac528f9 100644 --- a/src/main/java/top/r3944realms/lib39/core/event/CommonHandler.java +++ b/src/main/java/top/r3944realms/lib39/core/event/CommonHandler.java @@ -26,8 +26,13 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class CommonHandler { + @SuppressWarnings("unused") @net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Lib39.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE) public static class Game extends CommonHandler { + private static ServerLevel sl; + public ServerLevel getServerLevel() { + return sl; + } static volatile SyncData2Manager syncData2Manager; private static boolean isInitialized = false; public static SyncData2Manager getSyncData2Manager() { @@ -39,20 +44,22 @@ public class CommonHandler { if (event.getLevel().isClientSide() || !(event.getLevel() instanceof ServerLevel serverLevel)) return; // 只处理主世界(避免多次初始化) if (!serverLevel.dimension().equals(Level.OVERWORLD)) return; - synchronized (Game.class) { if (!isInitialized) { syncData2Manager = new SyncData2Manager(); MinecraftForge.EVENT_BUS.post(new SyncManagerRegisterEvent(syncData2Manager)); isInitialized = true; + sl = serverLevel; Lib39.LOGGER.info("SyncData2Manager initialized on world load"); } } } @SubscribeEvent - public static void onWorldLoad(LevelEvent.Unload event) { + public static void onWorldUnload(LevelEvent.Unload event) { if (event.getLevel().isClientSide() || !(event.getLevel() instanceof ServerLevel serverLevel)) return; if (!serverLevel.dimension().equals(Level.OVERWORLD)) return; + + sl = null; isInitialized = false; } @@ -88,6 +95,7 @@ public class CommonHandler { } } } + @SuppressWarnings("unused") @net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = Lib39.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD) public static class Mod extends CommonHandler { private static final Map, ResourceKey[]> itemAddMap = new ConcurrentHashMap<>();