diff options
Diffstat (limited to 'runtime/src/main/java')
3 files changed, 23 insertions, 6 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 8ba328334..78f118501 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -24,12 +24,15 @@ package me.shedaniel.rei; import me.shedaniel.architectury.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class RoughlyEnoughItemsInitializer { public static void onInitialize() { + RoughlyEnoughItemsState.env = isClient() ? EnvType.CLIENT : EnvType.SERVER; + RoughlyEnoughItemsState.isDev = isDev(); checkMods(); if (RoughlyEnoughItemsState.getErrors().isEmpty()) { @@ -83,6 +86,11 @@ public class RoughlyEnoughItemsInitializer { } @ExpectPlatform + public static boolean isDev() { + throw new AssertionError(); + } + + @ExpectPlatform public static void checkMods() { throw new AssertionError(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index 468ac0988..7ca37778f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -23,8 +23,7 @@ package me.shedaniel.rei; -import me.shedaniel.architectury.platform.Platform; -import me.shedaniel.architectury.utils.Env; +import net.fabricmc.api.EnvType; import net.minecraft.util.Tuple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -41,6 +40,8 @@ public class RoughlyEnoughItemsState { public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); + public static EnvType env; + public static boolean isDev; private static List<Tuple<String, String>> errors = new ArrayList<>(); private static List<Tuple<String, String>> warnings = new ArrayList<>(); private static Set<String> errorSet = new LinkedHashSet<>(); @@ -48,7 +49,7 @@ public class RoughlyEnoughItemsState { private static List<Runnable> continueCallbacks = new ArrayList<>(); public static void error(String reason) { - if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment()) + if (env == EnvType.SERVER || isDev) throw new RuntimeException(reason); if (RoughlyEnoughItemsState.errorSet.add(reason + " " + null)) { RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, null)); @@ -57,7 +58,7 @@ public class RoughlyEnoughItemsState { } public static void error(String reason, String link) { - if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment()) + if (env == EnvType.SERVER || isDev) throw new RuntimeException(reason + " " + link); if (RoughlyEnoughItemsState.errorSet.add(reason + " " + link)) { RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, link)); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java index e007f0ec8..b9e512bc9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java @@ -23,15 +23,19 @@ package me.shedaniel.rei.impl.client; +import me.shedaniel.architectury.annotations.ExpectPlatform; import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.rei.RoughlyEnoughItemsState; import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.InteractionResult; +import java.util.function.Consumer; + public class ErrorDisplayer { public void onInitializeClient() { - GuiEvent.INIT_PRE.register((screen, widgets, children) -> { + registerGuiInit((screen) -> { Minecraft minecraft = Minecraft.getInstance(); if ((!RoughlyEnoughItemsState.getErrors().isEmpty() || !RoughlyEnoughItemsState.getWarnings().isEmpty()) && !(screen instanceof WarningAndErrorScreen)) { WarningAndErrorScreen warningAndErrorScreen = new WarningAndErrorScreen("initialization", RoughlyEnoughItemsState.getWarnings(), RoughlyEnoughItemsState.getErrors(), (parent) -> { @@ -51,7 +55,11 @@ public class ErrorDisplayer { minecraft.screen = null; minecraft.setScreen(warningAndErrorScreen); } - return InteractionResult.PASS; }); } + + @ExpectPlatform + public static void registerGuiInit(Consumer<Screen> consumer) { + throw new AssertionError(); + } } |
