Skip to content

Commit

Permalink
Prevent crashing on servers
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianVennen committed Nov 20, 2024
1 parent da63951 commit 7a32488
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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());
}

Expand Down Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/irisshaders/iris/Oculus.java
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 7a32488

Please sign in to comment.