From ea614e1b9f1960354432f1d991b050a9113d86c6 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 27 Jul 2022 02:13:43 +0800 Subject: Make Architectury Plugin compile only --- .../shedaniel/rei/fabric/PluginDetectorImpl.java | 54 +++++----- .../rei/fabric/PrimitivePlatformAdapterImpl.java | 114 +++++++++++++++++++++ .../fabric/RoughlyEnoughItemsInitializerImpl.java | 108 ------------------- .../client/gui/fabric/ScreenOverlayImplFabric.java | 84 +++++++++++++++ .../client/gui/fabric/ScreenOverlayImplImpl.java | 83 --------------- .../plugin/common/fabric/DefaultPluginImpl.java | 65 ------------ 6 files changed, 228 insertions(+), 280 deletions(-) create mode 100644 fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java delete mode 100644 fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java create mode 100644 fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java delete mode 100644 fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java delete mode 100644 fabric/src/main/java/me/shedaniel/rei/plugin/common/fabric/DefaultPluginImpl.java (limited to 'fabric/src/main/java') 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 b42404dbf..b4c410f00 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

> void loadPlugin(Class pluginClass, Consumer> consumer) { Map 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.LOGGER.warn("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) 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>) (Class) REIPlugin.class, ((PluginView>) PluginManager.getInstance())::registerPlugin); } @Environment(EnvType.CLIENT) - public static void detectClientPlugins() { - loadPlugin(REIClientPlugin.class, ((PluginView) PluginManager.getClientInstance())::registerPlugin); - Supplier 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, TooltipComponent>) (lines, component) -> { - try { - method.get().invoke(null, lines, component); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - }, "clientTooltipComponentProvider"); + @Override + public Supplier detectClientPlugins() { + return () -> () -> { + loadPlugin(REIClientPlugin.class, ((PluginView) PluginManager.getClientInstance())::registerPlugin); + Supplier 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, 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/PrimitivePlatformAdapterImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java new file mode 100644 index 000000000..d60c19ed5 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PrimitivePlatformAdapterImpl.java @@ -0,0 +1,114 @@ +/* + * 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.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 PrimitivePlatformAdapterImpl implements PrimitivePlatformAdapter { + @Override + public boolean isClient() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; + } + + @Override + public void checkMods() { + ImmutableSet requiredModules = isClient() ? + ImmutableSet.builder() + .add("fabric-api-base") + .add("fabric-resource-loader-v0") + .add("fabric-networking-v0") + .add("fabric-lifecycle-events-v1") + .add("fabric-rendering-fluids-v1") + .build() : + ImmutableSet.builder() + .add("fabric-api-base") + .add("fabric-resource-loader-v0") + .add("fabric-networking-v0") + .add("fabric-lifecycle-events-v1") + .build(); + for (String module : requiredModules) { + boolean moduleLoaded = FabricLoader.getInstance().isModLoaded(module); + if (!moduleLoaded) { + RoughlyEnoughItemsState.error("Fabric API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/fabric-api/files/all"); + break; + } + } + if (!FabricLoader.getInstance().isModLoaded("architectury")) { + RoughlyEnoughItemsState.error("Architectury API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/architectury-api/files/all"); + } else { + Version version = FabricLoader.getInstance().getModContainer("architectury").get().getMetadata().getVersion(); + + try { + if (version instanceof SemanticVersion && SemanticVersion.parse("4.5.75").compareTo((SemanticVersion) version) > 0) { + RoughlyEnoughItemsState.error("Architectury API is too old, please update!", "https://www.curseforge.com/minecraft/mc-mods/architectury-api/files/all"); + } + } catch (VersionParsingException e) { + e.printStackTrace(); + } + } + if (isClient()) { + if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) { + RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); + } + } + } + + @Override + public boolean isDev() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); + } + + @Override + public String getMinecraftVersion() { + return FabricLoader.getInstance().getModContainer("minecraft").get().getMetadata().getVersion().getFriendlyString(); + } + + @Override + public int compareVersions(String version1, String version2) { + Version v1, v2; + + try { + v1 = SemanticVersion.parse(version1); + } catch (VersionParsingException e) { + new IllegalStateException("Failed to parse version: " + version1, e).printStackTrace(); + return 0; + } + + try { + v2 = SemanticVersion.parse(version2); + } catch (VersionParsingException e) { + new IllegalStateException("Failed to parse version: " + version2, e).printStackTrace(); + return 0; + } + + return v1.compareTo(v2); + } +} diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java deleted file mode 100644 index b6d51ff5f..000000000 --- a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java +++ /dev/null @@ -1,108 +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.fabric; - -import com.google.common.collect.ImmutableSet; -import me.shedaniel.rei.RoughlyEnoughItemsState; -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() { - return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; - } - - public static void checkMods() { - ImmutableSet requiredModules = isClient() ? - ImmutableSet.builder() - .add("fabric-api-base") - .add("fabric-resource-loader-v0") - .add("fabric-networking-v0") - .add("fabric-lifecycle-events-v1") - .add("fabric-rendering-fluids-v1") - .build() : - ImmutableSet.builder() - .add("fabric-api-base") - .add("fabric-resource-loader-v0") - .add("fabric-networking-v0") - .add("fabric-lifecycle-events-v1") - .build(); - for (String module : requiredModules) { - boolean moduleLoaded = FabricLoader.getInstance().isModLoaded(module); - if (!moduleLoaded) { - RoughlyEnoughItemsState.error("Fabric API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/fabric-api/files/all"); - break; - } - } - if (!FabricLoader.getInstance().isModLoaded("architectury")) { - RoughlyEnoughItemsState.error("Architectury API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/architectury-api/files/all"); - } else { - Version version = FabricLoader.getInstance().getModContainer("architectury").get().getMetadata().getVersion(); - - try { - if (version instanceof SemanticVersion && SemanticVersion.parse("4.5.75").compareTo((SemanticVersion) version) > 0) { - RoughlyEnoughItemsState.error("Architectury API is too old, please update!", "https://www.curseforge.com/minecraft/mc-mods/architectury-api/files/all"); - } - } catch (VersionParsingException e) { - e.printStackTrace(); - } - } - if (isClient()) { - if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) { - RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all"); - } - } - } - - public static boolean isDev() { - return FabricLoader.getInstance().isDevelopmentEnvironment(); - } - - public static String getMinecraftVersion() { - return FabricLoader.getInstance().getModContainer("minecraft").get().getMetadata().getVersion().getFriendlyString(); - } - - public static int compareVersions(String version1, String version2) { - Version v1, v2; - - try { - v1 = SemanticVersion.parse(version1); - } catch (VersionParsingException e) { - new IllegalStateException("Failed to parse version: " + version1, e).printStackTrace(); - return 0; - } - - try { - v2 = SemanticVersion.parse(version2); - } catch (VersionParsingException e) { - new IllegalStateException("Failed to parse version: " + version2, e).printStackTrace(); - return 0; - } - - return v1.compareTo(v2); - } -} diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java new file mode 100644 index 000000000..6972abc69 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplFabric.java @@ -0,0 +1,84 @@ +/* + * 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.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.ScreenOverlayImpl; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.world.inventory.tooltip.TooltipComponent; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class ScreenOverlayImplFabric extends ScreenOverlayImpl { + @Override + public void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) { + List lines = tooltip.entries().stream() + .flatMap(component -> { + if (component.isText()) { + List texts = Minecraft.getInstance().font.getSplitter().splitLines(component.getAsText(), 100000, Style.EMPTY); + Stream sequenceStream = texts.isEmpty() ? Stream.of(component.getAsText().getVisualOrderText()) + : texts.stream().map(Language.getInstance()::getVisualOrder); + return sequenceStream.map(ClientTooltipComponent::create); + } else if (((QueuedTooltip.TooltipEntryImpl) component).isClientComponent()) { + return Stream.of(component.getAsComponent()); + } else { + return Stream.empty(); + } + }) + .collect(Collectors.toList()); + for (Tooltip.Entry entry : tooltip.entries()) { + if (entry.isTooltipComponent()) { + TooltipComponent component = entry.getAsTooltipComponent(); + + if (component instanceof ClientTooltipComponent) break; + + try { + ClientInternals.getClientTooltipComponent(lines, component); + } catch (Throwable exception) { + throw new IllegalArgumentException("Failed to add tooltip component! " + component + ", Class: " + (component == null ? null : component.getClass().getCanonicalName()), exception); + } + } + } + renderTooltipInner(matrices, lines, tooltip.getX(), tooltip.getY()); + } + + public static void renderTooltipInner(PoseStack matrices, List lines, int mouseX, int mouseY) { + if (lines.isEmpty()) { + return; + } + matrices.pushPose(); + Minecraft.getInstance().screen.renderTooltipInternal(matrices, lines, mouseX, mouseY); + matrices.popPose(); + } +} 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/ScreenOverlayImplImpl.java deleted file mode 100644 index affa0859f..000000000 --- a/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java +++ /dev/null @@ -1,83 +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.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 net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; -import net.minecraft.locale.Language; -import net.minecraft.network.chat.FormattedText; -import net.minecraft.network.chat.Style; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.inventory.tooltip.TooltipComponent; - -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) { - List lines = tooltip.entries().stream() - .flatMap(component -> { - if (component.isText()) { - List texts = Minecraft.getInstance().font.getSplitter().splitLines(component.getAsText(), 100000, Style.EMPTY); - Stream sequenceStream = texts.isEmpty() ? Stream.of(component.getAsText().getVisualOrderText()) - : texts.stream().map(Language.getInstance()::getVisualOrder); - return sequenceStream.map(ClientTooltipComponent::create); - } else if (((QueuedTooltip.TooltipEntryImpl) component).isClientComponent()) { - return Stream.of(component.getAsComponent()); - } else { - return Stream.empty(); - } - }) - .collect(Collectors.toList()); - for (Tooltip.Entry entry : tooltip.entries()) { - if (entry.isTooltipComponent()) { - TooltipComponent component = entry.getAsTooltipComponent(); - - if (component instanceof ClientTooltipComponent) break; - - try { - ClientInternals.getClientTooltipComponent(lines, component); - } catch (Throwable exception) { - throw new IllegalArgumentException("Failed to add tooltip component! " + component + ", Class: " + (component == null ? null : component.getClass().getCanonicalName()), exception); - } - } - } - renderTooltipInner(matrices, lines, tooltip.getX(), tooltip.getY()); - } - - public static void renderTooltipInner(PoseStack matrices, List lines, int mouseX, int mouseY) { - if (lines.isEmpty()) { - return; - } - matrices.pushPose(); - Minecraft.getInstance().screen.renderTooltipInternal(matrices, lines, mouseX, mouseY); - matrices.popPose(); - } -} 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 = 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); - } -} -- cgit