From 7a3248878e6f411a3fd86244c01afd4457819cf1 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 11 May 2024 17:02:29 +0200 Subject: [PATCH] Prevent crashing on servers --- src/main/java/net/irisshaders/iris/Iris.java | 35 ++++++++----------- .../java/net/irisshaders/iris/Oculus.java | 15 ++++++++ 2 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 src/main/java/net/irisshaders/iris/Oculus.java diff --git a/src/main/java/net/irisshaders/iris/Iris.java b/src/main/java/net/irisshaders/iris/Iris.java index 28ef05acd5..5491fc7d51 100644 --- a/src/main/java/net/irisshaders/iris/Iris.java +++ b/src/main/java/net/irisshaders/iris/Iris.java @@ -34,15 +34,17 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.IExtensionPoint; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.loading.LoadingModList; @@ -69,10 +71,8 @@ import java.util.zip.ZipError; import java.util.zip.ZipException; -@Mod(Iris.MODID) +@EventBusSubscriber(bus = Bus.MOD, modid = Oculus.MODID, value = Dist.CLIENT) public class Iris { - public static final String MODID = "oculus"; - /** * The user-facing name of the mod. Moved into a constant to facilitate * easy branding changes (for forks). You'll still need to change this @@ -109,17 +109,11 @@ public class Iris { private static boolean loadPackWhenPossible = false; private static boolean renderSystemInit = false; - public Iris() { - try { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onKeyRegister); - MinecraftForge.EVENT_BUS.addListener(this::onKeyInput); - - IRIS_VERSION = ModList.get().getModContainerById(MODID).get().getModInfo().getVersion().toString(); - - ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new ShaderPackScreen(screen))); - ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); - }catch (Exception ignored) { - } + @SubscribeEvent + public static void onInitializeClient(FMLClientSetupEvent event) { + IRIS_VERSION = ModList.get().getModContainerById(Oculus.MODID).get().getModInfo().getVersion().toString(); + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, screen) -> new ShaderPackScreen(screen))); + MinecraftForge.EVENT_BUS.addListener(Iris::onKeyInput); } public static void loadShaderpackWhenPossible() { @@ -130,13 +124,14 @@ public static boolean isPackInUseQuick() { return pipelineManager.getPipelineNullable() instanceof IrisRenderingPipeline; } - public void onKeyRegister(RegisterKeyMappingsEvent event) { + @SubscribeEvent + public static void onKeyRegister(RegisterKeyMappingsEvent event) { event.register(reloadKeybind); event.register(toggleShadersKeybind); event.register(shaderpackScreenKeybind); } - public void onKeyInput(InputEvent.Key event) { + public static void onKeyInput(InputEvent.Key event) { handleKeybinds(Minecraft.getInstance()); } @@ -771,7 +766,7 @@ public static void onEarlyInitialize() { logger.warn("", e); } - irisConfig = new IrisConfig(FMLPaths.CONFIGDIR.get().resolve(MODID + ".properties")); + irisConfig = new IrisConfig(FMLPaths.CONFIGDIR.get().resolve(Oculus.MODID + ".properties")); try { irisConfig.initialize(); diff --git a/src/main/java/net/irisshaders/iris/Oculus.java b/src/main/java/net/irisshaders/iris/Oculus.java new file mode 100644 index 0000000000..30dddccc50 --- /dev/null +++ b/src/main/java/net/irisshaders/iris/Oculus.java @@ -0,0 +1,15 @@ +package net.irisshaders.iris; + +import net.minecraftforge.fml.IExtensionPoint; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.network.NetworkConstants; + +@Mod(Oculus.MODID) +public class Oculus { + public static final String MODID = "oculus"; + + public Oculus() { + ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); + } +}