aboutsummaryrefslogtreecommitdiff
path: root/fabric/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-07-27 02:13:43 +0800
committershedaniel <daniel@shedaniel.me>2022-07-27 02:13:43 +0800
commitf2345acc57d7d347507505a6976e20378bc0fbf9 (patch)
treedbff335e174954e836c95f9344390feb3750da43 /fabric/src/main/java
parent1d8b8e4e91adb33d208a5c3b4b2ccc36a0ef25a4 (diff)
downloadRoughlyEnoughItems-f2345acc57d7d347507505a6976e20378bc0fbf9.tar.gz
RoughlyEnoughItems-f2345acc57d7d347507505a6976e20378bc0fbf9.tar.bz2
RoughlyEnoughItems-f2345acc57d7d347507505a6976e20378bc0fbf9.zip
Make Architectury Plugin compile only
Diffstat (limited to 'fabric/src/main/java')
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java54
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java (renamed from fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java)18
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java (renamed from fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java)7
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/plugin/common/fabric/DefaultPluginImpl.java65
4 files changed, 46 insertions, 98 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
index 3b1a84061..07ba9c366 100644
--- a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java
@@ -26,11 +26,12 @@ package me.shedaniel.rei.fabric;
import com.google.common.base.Suppliers;
import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
-import me.shedaniel.rei.RoughlyEnoughItemsInitializer;
import me.shedaniel.rei.RoughlyEnoughItemsState;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.common.plugins.*;
import me.shedaniel.rei.impl.ClientInternals;
+import me.shedaniel.rei.impl.init.PluginDetector;
+import me.shedaniel.rei.impl.init.PrimitivePlatformAdapter;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
@@ -49,7 +50,7 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-public class PluginDetectorImpl {
+public class PluginDetectorImpl implements PluginDetector {
private static <P extends REIPlugin<?>> void loadPlugin(Class<? extends P> pluginClass, Consumer<? super REIPluginProvider<P>> consumer) {
Map<String, Env> entrypoints = new LinkedHashMap<>();
entrypoints.put("rei_server", Env.SERVER);
@@ -103,7 +104,7 @@ public class PluginDetectorImpl {
} catch (Throwable t) {
Throwable throwable = t;
while (throwable != null) {
- if (throwable.getMessage() != null && throwable.getMessage().contains("environment type SERVER") && !RoughlyEnoughItemsInitializer.isClient()) {
+ if (throwable.getMessage() != null && throwable.getMessage().contains("environment type SERVER") && !PrimitivePlatformAdapter.get().isClient()) {
RoughlyEnoughItemsState.error("Rerached side issue when loading REI plugin by %s. Please use \"rei_server\", \"rei_client\" or \"rei_common\" instead.".formatted(container.getProvider().getMetadata().getName()));
continue out;
}
@@ -122,7 +123,8 @@ public class PluginDetectorImpl {
return simpleName;
}
- public static void detectServerPlugins() {
+ @Override
+ public void detectServerPlugins() {
loadPlugin(REIServerPlugin.class, ((PluginView<REIServerPlugin>) PluginManager.getServerInstance())::registerPlugin);
try {
PluginView.getServerInstance().registerPlugin((REIServerPlugin) Class.forName("me.shedaniel.rei.impl.common.compat.FabricFluidAPISupportPlugin").getConstructor().newInstance());
@@ -132,29 +134,33 @@ public class PluginDetectorImpl {
}
@SuppressWarnings({"RedundantCast", "rawtypes"})
- public static void detectCommonPlugins() {
+ @Override
+ public void detectCommonPlugins() {
loadPlugin((Class<? extends REIPlugin<?>>) (Class) REIPlugin.class, ((PluginView<REIPlugin<?>>) PluginManager.getInstance())::registerPlugin);
}
@Environment(EnvType.CLIENT)
- public static void detectClientPlugins() {
- loadPlugin(REIClientPlugin.class, ((PluginView<REIClientPlugin>) PluginManager.getClientInstance())::registerPlugin);
- Supplier<Method> method = Suppliers.memoize(() -> {
- String methodName = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_437", "method_32635", "(Ljava/util/List;Lnet/minecraft/class_5632;)V");
- try {
- Method declaredMethod = Screen.class.getDeclaredMethod(methodName, List.class, TooltipComponent.class);
- if (declaredMethod != null) declaredMethod.setAccessible(true);
- return declaredMethod;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- });
- ClientInternals.attachInstance((BiConsumer<List<ClientTooltipComponent>, TooltipComponent>) (lines, component) -> {
- try {
- method.get().invoke(null, lines, component);
- } catch (IllegalAccessException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }, "clientTooltipComponentProvider");
+ @Override
+ public Supplier<Runnable> detectClientPlugins() {
+ return () -> () -> {
+ loadPlugin(REIClientPlugin.class, ((PluginView<REIClientPlugin>) PluginManager.getClientInstance())::registerPlugin);
+ Supplier<Method> method = Suppliers.memoize(() -> {
+ String methodName = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_437", "method_32635", "(Ljava/util/List;Lnet/minecraft/class_5632;)V");
+ try {
+ Method declaredMethod = Screen.class.getDeclaredMethod(methodName, List.class, TooltipComponent.class);
+ if (declaredMethod != null) declaredMethod.setAccessible(true);
+ return declaredMethod;
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ });
+ ClientInternals.attachInstance((BiConsumer<List<ClientTooltipComponent>, TooltipComponent>) (lines, component) -> {
+ try {
+ method.get().invoke(null, lines, component);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }, "clientTooltipComponentProvider");
+ };
}
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java
index 7c9e47573..e5eb4f542 100644
--- a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java
@@ -25,18 +25,21 @@ package me.shedaniel.rei.fabric;
import com.google.common.collect.ImmutableSet;
import me.shedaniel.rei.RoughlyEnoughItemsState;
+import me.shedaniel.rei.impl.init.PrimitivePlatformAdapter;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.SemanticVersion;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
-public class RoughlyEnoughItemsInitializerImpl {
- public static boolean isClient() {
+public class PrimitivePlatformAdapterImpl implements PrimitivePlatformAdapter {
+ @Override
+ public boolean isClient() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}
- public static void checkMods() {
+ @Override
+ public void checkMods() {
ImmutableSet<String> requiredModules = isClient() ?
ImmutableSet.<String>builder()
.add("fabric-api-base")
@@ -78,15 +81,18 @@ public class RoughlyEnoughItemsInitializerImpl {
}
}
- public static boolean isDev() {
+ @Override
+ public boolean isDev() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}
- public static String getMinecraftVersion() {
+ @Override
+ public String getMinecraftVersion() {
return FabricLoader.getInstance().getModContainer("minecraft").get().getMetadata().getVersion().getFriendlyString();
}
- public static int compareVersions(String version1, String version2) {
+ @Override
+ public int compareVersions(String version1, String version2) {
version1 = version1.contains("-") ? version1.substring(0, version1.indexOf("-")) : version1;
version2 = version2.contains("-") ? version2.substring(0, version2.indexOf("-")) : version2;
version1 = version1.contains("+") ? version1.substring(0, version1.indexOf("+")) : version1;
diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java
index 03a697957..2021b33aa 100644
--- a/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java
@@ -26,7 +26,7 @@ package me.shedaniel.rei.impl.client.gui.fabric;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.impl.ClientInternals;
-import me.shedaniel.rei.impl.client.gui.widget.QueuedTooltip;
+import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
@@ -40,8 +40,9 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-public class ScreenOverlayImplImpl {
- public static void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) {
+public class ScreenOverlayImplFabric extends ScreenOverlayImpl {
+ @Override
+ public void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) {
List<ClientTooltipComponent> lines = tooltip.entries().stream()
.flatMap(component -> {
if (component.isText()) {
diff --git a/fabric/src/main/java/me/shedaniel/rei/plugin/common/fabric/DefaultPluginImpl.java b/fabric/src/main/java/me/shedaniel/rei/plugin/common/fabric/DefaultPluginImpl.java
deleted file mode 100644
index e86a7cb50..000000000
--- a/fabric/src/main/java/me/shedaniel/rei/plugin/common/fabric/DefaultPluginImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * This file is licensed under the MIT License, part of Roughly Enough Items.
- * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package me.shedaniel.rei.plugin.common.fabric;
-
-import net.fabricmc.loader.api.FabricLoader;
-import net.minecraft.world.item.BucketItem;
-import net.minecraft.world.level.material.Fluid;
-import org.jetbrains.annotations.NotNull;
-
-import java.lang.reflect.Field;
-import java.util.Optional;
-
-public class DefaultPluginImpl {
- public static Fluid getFluidFromBucket(BucketItem item) {
- Field field = getContentField();
- if (field == null) return null;
- try {
- return (Fluid) field.get(item);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- private static Optional<Field> field = null;
-
- @NotNull
- private static Field getContentField() {
- if (field == null) {
- try {
- Field field = BucketItem.class.getDeclaredField(FabricLoader.getInstance().getMappingResolver().mapFieldName("intermediary", "net.minecraft.class_1755", "field_7905", "Lnet/minecraft/class_3611;"));
- field.setAccessible(true);
- DefaultPluginImpl.field = Optional.of(field);
- return field;
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- DefaultPluginImpl.field = Optional.empty();
- return null;
- }
- }
-
- return field.orElse(null);
- }
-}