Skip to content

Commit

Permalink
Fixed Forge server crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiYueCommentary committed Nov 16, 2024
1 parent 72d527f commit b845617
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
22 changes: 6 additions & 16 deletions forge/src/main/java/ziyue/tjmetro/forge/MainForge.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
24 changes: 24 additions & 0 deletions forge/src/main/java/ziyue/tjmetro/forge/MainForgeClient.java
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit b845617

Please sign in to comment.