diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-07-27 02:13:43 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-05-29 21:14:34 +0800 |
| commit | 5affcfca51424eb29db199eb4c7179eba15abed2 (patch) | |
| tree | a9dcbc64985e340714444f5f77e2589007c6509b /runtime/src/main/java | |
| parent | 87a8f87c2632e2250201623a2ac6ccec50bbca2d (diff) | |
| download | RoughlyEnoughItems-5affcfca51424eb29db199eb4c7179eba15abed2.tar.gz RoughlyEnoughItems-5affcfca51424eb29db199eb4c7179eba15abed2.tar.bz2 RoughlyEnoughItems-5affcfca51424eb29db199eb4c7179eba15abed2.zip | |
Make Architectury Plugin compile only
Diffstat (limited to 'runtime/src/main/java')
12 files changed, 87 insertions, 72 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 6cacc2396..1f15574e5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -35,7 +35,6 @@ import me.shedaniel.rei.api.common.plugins.PluginView; import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.registry.ReloadStage; -import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; import me.shedaniel.rei.impl.Internals; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.category.CategoryIdentifierImpl; @@ -55,6 +54,7 @@ import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl; import me.shedaniel.rei.impl.common.transfer.MenuInfoRegistryImpl; +import me.shedaniel.rei.impl.init.PluginDetector; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; import net.minecraft.util.Unit; @@ -63,6 +63,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.jetbrains.annotations.ApiStatus; +import java.util.ServiceLoader; import java.util.function.Function; import java.util.function.UnaryOperator; @@ -75,6 +76,7 @@ public class RoughlyEnoughItemsCore { new Log4JLogger(LogManager.getFormatterLogger("REI")) )), message -> "[REI] " + message); public static final PerformanceLogger PERFORMANCE_LOGGER = new PerformanceLoggerImpl(); + private static final ServiceLoader<PluginDetector> PLUGIN_DETECTOR_LOADER = ServiceLoader.load(PluginDetector.class); static { attachCommonInternals(); @@ -129,8 +131,9 @@ public class RoughlyEnoughItemsCore { } public void onInitialize() { - PluginDetector.detectCommonPlugins(); - PluginDetector.detectServerPlugins(); + PluginDetector detector = getPluginDetector(); + detector.detectCommonPlugins(); + detector.detectServerPlugins(); RoughlyEnoughItemsNetwork.onInitialize(); if (Platform.getEnvironment() == Env.SERVER) { @@ -143,4 +146,8 @@ public class RoughlyEnoughItemsCore { }); } } + + public static PluginDetector getPluginDetector() { + return PLUGIN_DETECTOR_LOADER.findFirst().orElseThrow(); + } } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 7d810ab80..d2469c67e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -226,7 +226,7 @@ public class RoughlyEnoughItemsCoreClient { public void onInitializeClient() { IssuesDetector.detect(); registerEvents(); - PluginDetector.detectClientPlugins(); + RoughlyEnoughItemsCore.getPluginDetector().detectClientPlugins().get().run(); loadTestPlugins(); Minecraft client = Minecraft.getInstance(); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index e68791be0..32e6e5c7a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -23,7 +23,6 @@ package me.shedaniel.rei; -import net.fabricmc.api.EnvType; import net.minecraft.util.Tuple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,7 +39,7 @@ public class RoughlyEnoughItemsState { public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); - public static EnvType env; + public static boolean client; public static boolean isDev; private static List<Tuple<String, String>> errors = new ArrayList<>(); private static List<Tuple<String, String>> warnings = new ArrayList<>(); @@ -49,7 +48,7 @@ public class RoughlyEnoughItemsState { private static List<Runnable> continueCallbacks = new ArrayList<>(); public static void error(String reason) { - if (env == EnvType.SERVER || isDev) + if (!client || isDev) throw new RuntimeException(reason); if (RoughlyEnoughItemsState.errorSet.add(reason + " " + null)) { RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, null)); @@ -58,7 +57,7 @@ public class RoughlyEnoughItemsState { } public static void error(String reason, String link) { - if (env == EnvType.SERVER || isDev) + if (!client || 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 2992fbce7..1b4bbdb61 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,12 +23,13 @@ package me.shedaniel.rei.impl.client; -import dev.architectury.injectables.annotations.ExpectPlatform; +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.function.UnaryOperator; public class ErrorDisplayer { @@ -54,8 +55,13 @@ public class ErrorDisplayer { }); } - @ExpectPlatform public static void registerGuiInit(UnaryOperator<Screen> consumer) { - throw new AssertionError(); + 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); + } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index f73bea3fa..a26a7c514 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -29,6 +29,7 @@ import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.architectury.event.events.client.ClientTickEvent; +import dev.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; @@ -56,6 +57,7 @@ import net.minecraft.world.InteractionResult; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; import java.util.*; import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @@ -151,7 +153,14 @@ public class REIRuntimeImpl implements REIRuntime { @Override public Optional<ScreenOverlay> getOverlay(boolean reset, boolean init) { if ((overlay == null && init) || reset) { - overlay = new ScreenOverlayImpl(); + try { + overlay = (ScreenOverlayImpl) Class.forName(Platform.isForge() ? "me.shedaniel.rei.impl.client.gui.forge.ScreenOverlayImplForge" + : "me.shedaniel.rei.impl.client.gui.fabric.ScreenOverlayImplFabric") + .getDeclaredConstructor() + .newInstance(); + } catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } overlay.init(); getSearchField().setFocused(false); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 2162a1320..7a105d0a6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -132,8 +132,8 @@ public class ConfigManagerImpl implements ConfigManager { Collections.singletonList(new FilteringEntry(220, value, ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules, defaultValue, saveConsumer, list -> ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules = Lists.newArrayList(list))); } , (field) -> field.getType() == List.class, ConfigObjectImpl.UseFilteringScreen.class); - saveConfig(); InternalLogger.getInstance().info("Config loaded"); + saveConfig(); } private static Jankson buildJankson(Jankson.Builder builder) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index 57fc72fd5..70ae68d59 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -27,7 +27,6 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import dev.architectury.injectables.annotations.ExpectPlatform; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -79,7 +78,7 @@ import java.util.Optional; import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @ApiStatus.Internal -public class ScreenOverlayImpl extends ScreenOverlay { +public abstract class ScreenOverlayImpl extends ScreenOverlay { private static final List<Tooltip> TOOLTIPS = Lists.newArrayList(); private static EntryListWidget entryListWidget = null; private static FavoritesListWidget favoritesListWidget = null; @@ -318,10 +317,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { renderTooltipInner(minecraft.screen, matrices, tooltip, tooltip.getX(), tooltip.getY()); } - @ExpectPlatform - public static void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) { - throw new AssertionError(); - } + protected abstract void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY); public void addTooltip(@Nullable Tooltip tooltip) { if (tooltip != null) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/credits/CreditsScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/credits/CreditsScreen.java index 04010bc54..39ca22c34 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/credits/CreditsScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/credits/CreditsScreen.java @@ -42,6 +42,7 @@ import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Tuple; import org.jetbrains.annotations.ApiStatus; +import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; @@ -116,6 +117,16 @@ public class CreditsScreen extends Screen { addButton(buttonDone = new Button(width / 2 - 100, height - 26, 200, 20, new TranslatableComponent("gui.done"), button -> openPrevious())); } + private static void fillTranslators(Exception[] exception, List<Tuple<String, List<TranslatorEntry>>> translators) { + try { + Class.forName("me.shedaniel.rei.impl.client.gui.credits.%s.CreditsScreenImpl".formatted(Platform.isForge() ? "forge" : "fabric")) + .getDeclaredMethod("fillTranslators", Exception[].class, List.class) + .invoke(null, exception, translators); + } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + private void openPrevious() { Minecraft.getInstance().setScreen(parent); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/DeferringEntryTypeProviderImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/DeferringEntryTypeProviderImpl.java index b483ef812..f0a49f209 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/DeferringEntryTypeProviderImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/DeferringEntryTypeProviderImpl.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.impl.common.entry; import me.shedaniel.architectury.platform.Platform; +import dev.architectury.utils.Env; import me.shedaniel.rei.api.client.gui.Renderer; import me.shedaniel.rei.api.common.entry.type.BuiltinEntryTypes; import me.shedaniel.rei.api.common.entry.type.EntryDefinition; @@ -52,7 +53,7 @@ public enum DeferringEntryTypeProviderImpl implements Function<ResourceLocation, public EntryType<?> apply(ResourceLocation id) { if (id.equals(BuiltinEntryTypes.EMPTY_ID)) { return typeCache.computeIfAbsent(id, this::emptyType); - } else if (id.equals(RENDERING_ID) && Platform.getEnv() == EnvType.CLIENT) { + } else if (id.equals(RENDERING_ID) && Platform.getEnvironment() == Env.CLIENT) { return typeCache.computeIfAbsent(id, this::renderingType); } return typeCache.computeIfAbsent(id, EntryTypeDeferred::new); diff --git a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java b/runtime/src/main/java/me/shedaniel/rei/impl/init/PluginDetector.java index b24d30075..228b65eeb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/init/PluginDetector.java @@ -21,26 +21,16 @@ * SOFTWARE. */ -package me.shedaniel.rei; +package me.shedaniel.rei.impl.init; -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; +import java.util.function.Supplier; -public class PluginDetector { - @ExpectPlatform - public static void detectServerPlugins() { - throw new AssertionError(); - } +public interface PluginDetector { + void detectServerPlugins(); - @ExpectPlatform - public static void detectCommonPlugins() { - throw new AssertionError(); - } + void detectCommonPlugins(); - @Environment(EnvType.CLIENT) - @ExpectPlatform - public static void detectClientPlugins() { - throw new AssertionError(); + default Supplier<Runnable> detectClientPlugins() { + return () -> () -> {}; } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/init/PrimitivePlatformAdapter.java b/runtime/src/main/java/me/shedaniel/rei/impl/init/PrimitivePlatformAdapter.java new file mode 100644 index 000000000..fc4d16d9c --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/init/PrimitivePlatformAdapter.java @@ -0,0 +1,21 @@ +package me.shedaniel.rei.impl.init; + +import java.util.ServiceLoader; + +public interface PrimitivePlatformAdapter { + ServiceLoader<PrimitivePlatformAdapter> LOADER = ServiceLoader.load(PrimitivePlatformAdapter.class); + + static PrimitivePlatformAdapter get() { + return LOADER.findFirst().orElseThrow(); + } + + boolean isClient(); + + boolean isDev(); + + void checkMods(); + + String getMinecraftVersion(); + + int compareVersions(String version1, String version2); +} diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/impl/init/RoughlyEnoughItemsInitializer.java index c0cf98a41..4f3d9fb52 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/init/RoughlyEnoughItemsInitializer.java @@ -21,10 +21,9 @@ * SOFTWARE. */ -package me.shedaniel.rei; +package me.shedaniel.rei.impl.init; -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.fabricmc.api.EnvType; +import me.shedaniel.rei.RoughlyEnoughItemsState; import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; @@ -35,15 +34,16 @@ public class RoughlyEnoughItemsInitializer { public static final String COMPATIBLE_MC_VERSION_HIGH = "1.17"; public static void onInitialize() { - RoughlyEnoughItemsState.env = isClient() ? EnvType.CLIENT : EnvType.SERVER; - RoughlyEnoughItemsState.isDev = isDev(); - - String minecraftVersion = getMinecraftVersion(); - if (minecraftVersion.startsWith("1.") && (compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_LOW) < 0 || compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_HIGH) >= 0)) { + PrimitivePlatformAdapter adapter = PrimitivePlatformAdapter.get(); + RoughlyEnoughItemsState.client = adapter.isClient(); + RoughlyEnoughItemsState.isDev = adapter.isDev(); + + String minecraftVersion = adapter.getMinecraftVersion(); + if (minecraftVersion.startsWith("1.") && (adapter.compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_LOW) < 0 || adapter.compareVersions(minecraftVersion, COMPATIBLE_MC_VERSION_HIGH) >= 0)) { RoughlyEnoughItemsState.error("Your current REI version (for >=" + COMPATIBLE_MC_VERSION_LOW + " and <" + COMPATIBLE_MC_VERSION_HIGH + ") is not compatible with your current Minecraft version (" + minecraftVersion + ")."); } - checkMods(); + adapter.checkMods(); if (RoughlyEnoughItemsState.getErrors().isEmpty()) { initializeEntryPoint(false, "me.shedaniel.rei.RoughlyEnoughItemsCore"); @@ -67,7 +67,7 @@ public class RoughlyEnoughItemsInitializer { Object instance = name.getConstructor().newInstance(); Method method = null; if (client) { - if (isClient()) { + if (PrimitivePlatformAdapter.get().isClient()) { try { method = name.getDeclaredMethod("onInitializeClient"); } catch (NoSuchMethodException ignored) { @@ -89,29 +89,4 @@ public class RoughlyEnoughItemsInitializer { throw new RuntimeException("Failed to initialize REI entry point: " + className, e); } } - - @ExpectPlatform - public static boolean isClient() { - throw new AssertionError(); - } - - @ExpectPlatform - public static boolean isDev() { - throw new AssertionError(); - } - - @ExpectPlatform - public static void checkMods() { - throw new AssertionError(); - } - - @ExpectPlatform - public static String getMinecraftVersion() { - throw new AssertionError(); - } - - @ExpectPlatform - public static int compareVersions(String version1, String version2) { - throw new AssertionError(); - } }
\ No newline at end of file |
