diff options
4 files changed, 13 insertions, 11 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java index 7e3b8e188..d3572dfc9 100644 --- a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java +++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.fabric; +import me.shedaniel.rei.impl.client.ErrorDisplayer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -31,10 +32,11 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.UnaryOperator; -public class ErrorDisplayerImpl { +public class ErrorDisplayerImpl implements ErrorDisplayer.ErrorGuiInitializer { public static List<Consumer<Screen>> consumerList = new ArrayList<>(); - public static void registerGuiInit(UnaryOperator<Screen> consumer) { + @Override + public void registerGuiInit(UnaryOperator<Screen> consumer) { consumerList.add(screen -> { if (screen != Minecraft.getInstance().screen) return; Screen screen1 = consumer.apply(screen); diff --git a/fabric/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer b/fabric/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer new file mode 100644 index 000000000..511737e2f --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.fabric.ErrorDisplayerImpl
\ No newline at end of file diff --git a/forge/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer b/forge/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer new file mode 100644 index 000000000..34c93bd88 --- /dev/null +++ b/forge/src/main/resources/META-INF/services/me.shedaniel.rei.impl.client.ErrorDisplayer$ErrorGuiInitializer @@ -0,0 +1 @@ +me.shedaniel.rei.impl.client.forge.ErrorDisplayerImpl
\ No newline at end of file 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 1b4bbdb61..29b7accfe 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,13 +23,12 @@ package me.shedaniel.rei.impl.client; -import dev.architectury.platform.Platform; 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 java.lang.reflect.InvocationTargetException; +import java.util.ServiceLoader; import java.util.function.UnaryOperator; public class ErrorDisplayer { @@ -56,12 +55,11 @@ public class ErrorDisplayer { } public static void registerGuiInit(UnaryOperator<Screen> consumer) { - try { - Class.forName("me.shedaniel.rei.impl.client.%s.ErrorDisplayerImpl".formatted(Platform.isForge() ? "forge" : "fabric")) - .getDeclaredMethod("registerGuiInit", UnaryOperator.class) - .invoke(null, consumer); - } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) { - throw new RuntimeException(e); - } + ErrorGuiInitializer initializer = ServiceLoader.load(ErrorGuiInitializer.class).findFirst().orElseThrow(); + initializer.registerGuiInit(consumer); + } + + public interface ErrorGuiInitializer { + void registerGuiInit(UnaryOperator<Screen> consumer); } } |
