From b845617b6f43af51ddb5578c3f6073a06697b672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=90=E6=82=A6=E8=A7=A3=E8=AF=B4?= Date: Sat, 16 Nov 2024 21:27:24 +0800 Subject: [PATCH] Fixed Forge server crash --- .../java/ziyue/tjmetro/forge/MainForge.java | 22 +++++------------ .../ziyue/tjmetro/forge/MainForgeClient.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 forge/src/main/java/ziyue/tjmetro/forge/MainForgeClient.java diff --git a/forge/src/main/java/ziyue/tjmetro/forge/MainForge.java b/forge/src/main/java/ziyue/tjmetro/forge/MainForge.java index 0aee1ac..3fd7aa4 100644 --- a/forge/src/main/java/ziyue/tjmetro/forge/MainForge.java +++ b/forge/src/main/java/ziyue/tjmetro/forge/MainForge.java @@ -1,17 +1,15 @@ package ziyue.tjmetro.forge; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import org.mtr.mapping.holder.Screen; import ziyue.tjmetro.mod.Reference; import ziyue.tjmetro.mod.TianjinMetro; import ziyue.tjmetro.mod.TianjinMetroClient; import ziyue.tjmetro.mod.client.Filters; -import ziyue.tjmetro.mod.screen.ConfigClientScreen; /** * @since 1.0.0-beta-1 @@ -24,23 +22,15 @@ public final class MainForge public MainForge() { TianjinMetro.init(); - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> TianjinMetroClient::init); - MinecraftForge.EVENT_BUS.register(this); - - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () ->{ -#if MC_VERSION <= "11605" - ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.fml.ExtensionPoint.CONFIGGUIFACTORY, () -> (client, parent) -> new ConfigClientScreen(new Screen(parent))); -#elif MC_VERSION <= "11701" - ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.fmlclient.ConfigGuiHandler.ConfigGuiFactory.class, () -> new net.minecraftforge.fmlclient.ConfigGuiHandler.ConfigGuiFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); -#elif MC_VERSION <= "11802" - ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory.class, () -> new net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); -#elif MC_VERSION <= "12004" - ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory.class, () -> new net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); -#endif + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { + TianjinMetroClient.init(); + MainForgeClient.registerConfigMenu(); }); + MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent + @OnlyIn(Dist.CLIENT) public void afterRegistry( #if MC_VERSION <= "11701" net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent.Post event diff --git a/forge/src/main/java/ziyue/tjmetro/forge/MainForgeClient.java b/forge/src/main/java/ziyue/tjmetro/forge/MainForgeClient.java new file mode 100644 index 0000000..27baab6 --- /dev/null +++ b/forge/src/main/java/ziyue/tjmetro/forge/MainForgeClient.java @@ -0,0 +1,24 @@ +package ziyue.tjmetro.forge; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; +import org.mtr.mapping.holder.Screen; +import ziyue.tjmetro.mod.client.Filters; +import ziyue.tjmetro.mod.screen.ConfigClientScreen; + +public class MainForgeClient +{ + public static void registerConfigMenu() { +#if MC_VERSION <= "11605" + ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.fml.ExtensionPoint.CONFIGGUIFACTORY, () -> (client, parent) -> new ConfigClientScreen(new Screen(parent))); +#elif MC_VERSION <= "11701" + ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.fmlclient.ConfigGuiHandler.ConfigGuiFactory.class, () -> new net.minecraftforge.fmlclient.ConfigGuiHandler.ConfigGuiFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); +#elif MC_VERSION <= "11802" + ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory.class, () -> new net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); +#elif MC_VERSION <= "12004" + ModLoadingContext.get().registerExtensionPoint(net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory.class, () -> new net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory((client, parent) -> new ConfigClientScreen(new Screen(parent)))); +#endif + } +}