From b866becfb620c02a74fb990915001e154b5d2b0b Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 2 Aug 2021 19:54:29 +0800 Subject: Welcome, Forge 1.17 --- .../rei/api/client/gui/widgets/Tooltip.java | 5 + build.gradle | 4 +- .../autocrafting/DefaultRecipeBookHandler.java | 99 -------- .../recipebook/DefaultRecipeBookHandler.java | 99 ++++++++ .../rei/plugin/client/DefaultClientPlugin.java | 2 +- .../client/gui/fabric/ScreenOverlayImplImpl.java | 72 ++++++ fabric/src/main/resources/fabric.mod.json | 4 +- forge/build.gradle | 36 +-- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 4 +- .../rei/forge/RoughlyEnoughItemsForge.java | 8 +- .../client/gui/forge/ScreenOverlayImplImpl.java | 45 ++++ .../client/forge/DefaultClientPluginImpl.java | 8 +- .../rei/plugin/common/forge/DefaultPluginImpl.java | 8 +- .../main/resources/META-INF/accesstransformer.cfg | 71 +++--- forge/src/main/resources/META-INF/mods.toml | 6 +- gradle.properties | 12 +- .../rei/impl/client/gui/ScreenOverlayImpl.java | 32 +-- .../rei/impl/client/gui/widget/QueuedTooltip.java | 13 ++ .../rei/impl/common/entry/AbstractEntryStack.java | 1 + .../plugin/client/DefaultClientRuntimePlugin.java | 252 --------------------- .../client/runtime/DefaultClientRuntimePlugin.java | 252 +++++++++++++++++++++ .../rei/plugin/common/DefaultRuntimePlugin.java | 60 ----- .../common/runtime/DefaultRuntimePlugin.java | 60 +++++ settings.gradle | 4 +- 24 files changed, 640 insertions(+), 517 deletions(-) delete mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java create mode 100644 default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java create mode 100644 fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java create mode 100644 forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/common/DefaultRuntimePlugin.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index 099061658..919644e09 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.api.client.gui.widgets; import dev.architectury.utils.EnvExecutor; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; @@ -128,6 +129,10 @@ public interface Tooltip { return this; } + EntryStack getContextStack(); + + Tooltip withContextStack(EntryStack stack); + default void queue() { EnvExecutor.runInEnv(EnvType.CLIENT, () -> () -> REIRuntime.getInstance().queueTooltip(this)); } diff --git a/build.gradle b/build.gradle index e16f723dc..c888cb901 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id("architectury-plugin") version("3.2-SNAPSHOT") - id("dev.architectury.loom") version("0.9.0-SNAPSHOT") apply false + id("architectury-plugin") version("3.3-SNAPSHOT") + id("dev.architectury.loom") version("0.7.4-SNAPSHOT") apply false id("org.cadixdev.licenser") version("0.5.0") id("com.matthewprenger.cursegradle") version("1.4.0") id("java") diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java deleted file mode 100644 index 6406429d1..000000000 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultRecipeBookHandler.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021 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.autocrafting; - -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; -import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay; -import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.world.inventory.CraftingMenu; -import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.inventory.RecipeBookMenu; -import net.minecraft.world.item.crafting.Recipe; - -@Environment(EnvType.CLIENT) -public class DefaultRecipeBookHandler implements TransferHandler { - @Override - public Result handle(Context context) { - if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets()) - return Result.createNotApplicable(); - Display display = context.getDisplay(); - if (!(context.getMenu() instanceof RecipeBookMenu container)) - return Result.createNotApplicable(); - if (container == null) - return Result.createNotApplicable(); - if (display instanceof DefaultCraftingDisplay craftingDisplay) { - if (craftingDisplay.getOptionalRecipe().isPresent()) { - int h = -1, w = -1; - if (container instanceof CraftingMenu) { - h = 3; - w = 3; - } else if (container instanceof InventoryMenu) { - h = 2; - w = 2; - } - if (h == -1 || w == -1) - return Result.createNotApplicable(); - Recipe recipe = craftingDisplay.getOptionalRecipe().get(); - if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w) - return Result.createFailed(new TranslatableComponent("error.rei.transfer.too_small", h, w)); - if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) - return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); - if (!context.isActuallyCrafting()) - return Result.createSuccessful(); - context.getMinecraft().setScreen(context.getContainerScreen()); - if (context.getContainerScreen() instanceof RecipeUpdateListener) - ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); - context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); - return Result.createSuccessful(); - } - } else if (display instanceof DefaultCookingDisplay defaultDisplay) { - if (defaultDisplay.getOptionalRecipe().isPresent()) { - Recipe recipe = (defaultDisplay).getOptionalRecipe().get(); - if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) - return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); - if (!context.isActuallyCrafting()) - return Result.createSuccessful(); - context.getMinecraft().setScreen(context.getContainerScreen()); - if (context.getContainerScreen() instanceof RecipeUpdateListener) - ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); - context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); - return Result.createSuccessful(); - } - } - return Result.createNotApplicable(); - } - - @Override - public double getPriority() { - return -20; - } -} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java new file mode 100644 index 000000000..9de8162ae --- /dev/null +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/autocrafting/recipebook/DefaultRecipeBookHandler.java @@ -0,0 +1,99 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.autocrafting.recipebook; + +import me.shedaniel.rei.api.client.ClientHelper; +import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; +import me.shedaniel.rei.plugin.common.displays.cooking.DefaultCookingDisplay; +import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.inventory.CraftingMenu; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.RecipeBookMenu; +import net.minecraft.world.item.crafting.Recipe; + +@Environment(EnvType.CLIENT) +public class DefaultRecipeBookHandler implements TransferHandler { + @Override + public Result handle(Context context) { + if (context.getDisplay() instanceof SimpleGridMenuDisplay && ClientHelper.getInstance().canUseMovePackets()) + return Result.createNotApplicable(); + Display display = context.getDisplay(); + if (!(context.getMenu() instanceof RecipeBookMenu container)) + return Result.createNotApplicable(); + if (container == null) + return Result.createNotApplicable(); + if (display instanceof DefaultCraftingDisplay craftingDisplay) { + if (craftingDisplay.getOptionalRecipe().isPresent()) { + int h = -1, w = -1; + if (container instanceof CraftingMenu) { + h = 3; + w = 3; + } else if (container instanceof InventoryMenu) { + h = 2; + w = 2; + } + if (h == -1 || w == -1) + return Result.createNotApplicable(); + Recipe recipe = craftingDisplay.getOptionalRecipe().get(); + if (craftingDisplay.getHeight() > h || craftingDisplay.getWidth() > w) + return Result.createFailed(new TranslatableComponent("error.rei.transfer.too_small", h, w)); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().setScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeUpdateListener) + ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); + context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } else if (display instanceof DefaultCookingDisplay defaultDisplay) { + if (defaultDisplay.getOptionalRecipe().isPresent()) { + Recipe recipe = (defaultDisplay).getOptionalRecipe().get(); + if (!context.getMinecraft().player.getRecipeBook().contains(recipe)) + return Result.createFailed(new TranslatableComponent("error.rei.recipe.not.unlocked")); + if (!context.isActuallyCrafting()) + return Result.createSuccessful(); + context.getMinecraft().setScreen(context.getContainerScreen()); + if (context.getContainerScreen() instanceof RecipeUpdateListener) + ((RecipeUpdateListener) context.getContainerScreen()).getRecipeBookComponent().ghostRecipe.clear(); + context.getMinecraft().gameMode.handlePlaceRecipe(container.containerId, recipe, Screen.hasShiftDown()); + return Result.createSuccessful(); + } + } + return Result.createNotApplicable(); + } + + @Override + public double getPriority() { + return -20; + } +} diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index ae38726c3..2bb9c0925 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -48,7 +48,7 @@ import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.ClientInternals; -import me.shedaniel.rei.plugin.autocrafting.DefaultRecipeBookHandler; +import me.shedaniel.rei.plugin.autocrafting.recipebook.DefaultRecipeBookHandler; import me.shedaniel.rei.plugin.client.categories.*; import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconBaseCategory; import me.shedaniel.rei.plugin.client.categories.beacon.DefaultBeaconPaymentCategory; 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 new file mode 100644 index 000000000..2e25b84b4 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/gui/fabric/ScreenOverlayImplImpl.java @@ -0,0 +1,72 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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 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.Style; +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()) { + return Minecraft.getInstance().font.getSplitter().splitLines(component.getAsText(), 100000, Style.EMPTY).stream() + .map(Language.getInstance()::getVisualOrder) + .map(ClientTooltipComponent::create); + } else { + return Stream.of(component.getAsComponent()); + } + }) + .collect(Collectors.toList()); + for (TooltipComponent component : tooltip.components()) { + 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(); + matrices.translate(0, 0, 500); + Minecraft.getInstance().screen.renderTooltipInternal(matrices, lines, mouseX, mouseY); + matrices.popPose(); + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 4c417b3af..75b337f06 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -24,9 +24,9 @@ ], "rei": [ "me.shedaniel.rei.plugin.common.DefaultPlugin", - "me.shedaniel.rei.plugin.common.DefaultRuntimePlugin", + "me.shedaniel.rei.plugin.common.runtime.DefaultRuntimePlugin", "me.shedaniel.rei.plugin.client.DefaultClientPlugin", - "me.shedaniel.rei.plugin.client.DefaultClientRuntimePlugin" + "me.shedaniel.rei.plugin.client.runtime.DefaultClientRuntimePlugin" ] }, "accessWidener": "roughlyenoughitems.accessWidener", diff --git a/forge/build.gradle b/forge/build.gradle index 031a5db6f..8f6f01ea8 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "5.0.0" + id "com.github.johnrengelman.shadow" version "7.0.0" } configurations { @@ -33,35 +33,35 @@ repositories { dependencies { forge("net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}") modApi("me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}") - modApi("me.shedaniel:architectury-forge:${architectury_version}") + modApi("dev.architectury:architectury-forge:${architectury_version}") implementation(project(path: ":api")) { transitive = false } implementation(project(path: ":default-plugin")) { transitive = false } implementation(project(path: ":runtime")) { transitive = false } implementation(project(path: ":jei-compatibility-layer")) { transitive = false } - implementation(project(path: ":jei-internals-workaround")) { transitive = false } + // implementation(project(path: ":jei-internals-workaround")) { transitive = false } developmentForge(project(path: ":api")) { transitive = false } developmentForge(project(path: ":default-plugin")) { transitive = false } developmentForge(project(path: ":runtime")) { transitive = false } developmentForge(project(path: ":jei-compatibility-layer")) { transitive = false } - developmentForge(project(path: ":jei-internals-workaround")) { transitive = false } + // developmentForge(project(path: ":jei-internals-workaround")) { transitive = false } shadowCommon(project(path: ":api", configuration: "transformProductionForge")) { transitive = false } shadowCommon(project(path: ":default-plugin", configuration: "transformProductionForge")) { transitive = false } shadowCommon(project(path: ":runtime", configuration: "transformProductionForge")) { transitive = false } shadowCommon(project(path: ":jei-compatibility-layer")) { transitive = false } - modRuntime("curse.maven:chiselsbits-231095:3176033") - modRuntime("curse.maven:jumbofurnace-390880:3120970") - modRuntime("curse.maven:cyclic-239286:3221427") - modRuntime("curse.maven:mekanism-268560:3206392") - modRuntime("curse.maven:refined-storage-243076:3196167") - modRuntime("appeng:appliedenergistics2:8.2.0") - modRuntime("curse.maven:tcon-74072:3273213") - modRuntime("curse.maven:mantle-74924:3273201") - modRuntime("curse.maven:jer-240630:3066754") - modRuntime("curse.maven:jep-417645:3198370") - modRuntime("curse.maven:simple-storage-network-268495:3257204") + // modRuntime("curse.maven:chiselsbits-231095:3176033") + // modRuntime("curse.maven:jumbofurnace-390880:3120970") + // modRuntime("curse.maven:cyclic-239286:3221427") + // modRuntime("curse.maven:mekanism-268560:3206392") + // modRuntime("curse.maven:refined-storage-243076:3196167") + // modRuntime("appeng:appliedenergistics2:8.2.0") + // modRuntime("curse.maven:tcon-74072:3273213") + // modRuntime("curse.maven:mantle-74924:3273201") + // modRuntime("curse.maven:jer-240630:3066754") + // modRuntime("curse.maven:jep-417645:3198370") + // modRuntime("curse.maven:simple-storage-network-268495:3257204") } shadowJar { @@ -84,11 +84,11 @@ curseforge { apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key') project { id = "392060" - releaseType = "beta" + releaseType = "release" changelogType = "html" changelog = rootProject.releaseChangelog - addGameVersion "1.16.4" - addGameVersion "1.16.5" + addGameVersion "1.17" + addGameVersion "1.17.1" addGameVersion "Java 8" addGameVersion "Forge" relations { diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index e299054c0..8ee7a0a99 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -32,8 +32,9 @@ import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.jeicompat.JEIPluginDetector; import me.shedaniel.rei.plugin.client.DefaultClientPlugin; -import me.shedaniel.rei.plugin.client.DefaultClientRuntimePlugin; +import me.shedaniel.rei.plugin.client.runtime.DefaultClientRuntimePlugin; import me.shedaniel.rei.plugin.common.DefaultPlugin; +import me.shedaniel.rei.plugin.common.runtime.DefaultRuntimePlugin; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -69,6 +70,7 @@ public class PluginDetectorImpl { public static void detectServerPlugins() { PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultPlugin())); + PluginView.getServerInstance().registerPlugin(wrapPlugin(Collections.singletonList("roughlyenoughitems"), new DefaultRuntimePlugin())); RoughlyEnoughItemsForge.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); diff --git a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java index 61593fd84..db5da78bd 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsForge.java @@ -67,21 +67,21 @@ public class RoughlyEnoughItemsForge { .map(IModInfo::getModId) .collect(Collectors.toList()); for (ModFileScanData.AnnotationData annotation : data.getAnnotations()) { - if (annotationType.equals(annotation.getAnnotationType())) { + if (annotationType.equals(annotation.targetType())) { try { - Class clazz = (Class) Class.forName(annotation.getMemberName()); + Class clazz = (Class) Class.forName(annotation.memberName()); if (predicate.test(clazz)) { instances.add(new ImmutablePair<>(modIds, () -> { try { return clazz.getDeclaredConstructor().newInstance(); } catch (Throwable throwable) { - LOGGER.error("Failed to load plugin: " + annotation.getMemberName(), throwable); + LOGGER.error("Failed to load plugin: " + annotation.memberName(), throwable); return null; } })); } } catch (Throwable throwable) { - LOGGER.error("Failed to load plugin: " + annotation.getMemberName(), throwable); + LOGGER.error("Failed to load plugin: " + annotation.memberName(), throwable); } } } diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplImpl.java new file mode 100644 index 000000000..1b27ecf80 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/gui/forge/ScreenOverlayImplImpl.java @@ -0,0 +1,45 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.forge; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.common.entry.EntryStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fmlclient.gui.GuiUtils; + +public class ScreenOverlayImplImpl { + public static void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) { + matrices.pushPose(); + matrices.translate(0, 0, 500); + EntryStack stack = tooltip.getContextStack(); + ItemStack itemStack = stack.getValue() instanceof ItemStack ? stack.castValue() : ItemStack.EMPTY; + GuiUtils.preItemToolTip(itemStack); + GuiUtils.drawHoveringText(matrices, tooltip.getText(), mouseX, mouseY, screen.width, screen.height, screen.width, Minecraft.getInstance().font); + GuiUtils.postItemToolTip(); + matrices.popPose(); + } +} diff --git a/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java index 7c47d1c84..9ad85f452 100644 --- a/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java @@ -42,9 +42,9 @@ public class DefaultClientPluginImpl { Set potions = Sets.newLinkedHashSet(); for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { for (PotionBrewing.Mix mix : PotionBrewing.POTION_MIXES) { - IRegistryDelegate from = mix.from; + IRegistryDelegate from = mix.f_43532_; Ingredient ingredient = mix.ingredient; - IRegistryDelegate to = mix.to; + IRegistryDelegate to = mix.f_43534_; Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) .map(ItemStack::copy) .map(stack -> PotionUtils.setPotion(stack, from.get()))); @@ -59,9 +59,9 @@ public class DefaultClientPluginImpl { } for (Potion potion : potions) { for (PotionBrewing.Mix mix : PotionBrewing.CONTAINER_MIXES) { - IRegistryDelegate from = mix.from; + IRegistryDelegate from = mix.f_43532_; Ingredient ingredient = mix.ingredient; - IRegistryDelegate to = mix.to; + IRegistryDelegate to = mix.f_43534_; Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from.get()), potion)); ItemStack output = PotionUtils.setPotion(new ItemStack(to.get()), potion); clientPlugin.registerBrewingRecipe(base, ingredient, output); diff --git a/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java b/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java index bc7780d11..cc87da5b9 100644 --- a/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/plugin/common/forge/DefaultPluginImpl.java @@ -24,10 +24,10 @@ package me.shedaniel.rei.plugin.common.forge; import com.google.common.base.Predicates; -import dev.architectury.hooks.forge.FluidStackHooksForge; +import dev.architectury.event.CompoundEventResult; +import dev.architectury.hooks.fluid.forge.FluidStackHooksForge; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; @@ -44,7 +44,7 @@ public class DefaultPluginImpl { if (handlerOptional.isPresent()) { IFluidHandlerItem handler = handlerOptional.orElse(null); if (handler.getTanks() > 0) { - return InteractionResultHolder.success(IntStream.range(0, handler.getTanks()) + return CompoundEventResult.interruptTrue(IntStream.range(0, handler.getTanks()) .mapToObj(handler::getFluidInTank) .filter(Predicates.not(FluidStack::isEmpty)) .map(FluidStackHooksForge::fromForge) @@ -52,7 +52,7 @@ public class DefaultPluginImpl { } } - return InteractionResultHolder.pass(null); + return CompoundEventResult.pass(); }); } } diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index 572494c09..908d28af2 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -1,32 +1,39 @@ -public net.minecraft.client.gui.FontRenderer$CharacterRenderer -public net.minecraft.potion.PotionBrewing$MixPredicate -public net.minecraft.client.gui.widget.button.ImageButton field_191750_o -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147006_u -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147000_g -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_146999_f -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147007_t -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147003_i -public net.minecraft.client.gui.screen.inventory.ContainerScreen field_147009_r -public net.minecraft.client.gui.DisplayEffectsScreen field_147045_u -public net.minecraft.client.gui.recipebook.RecipeBookGui field_191915_z -public net.minecraft.client.gui.recipebook.RecipeBookGui field_193962_q -public net.minecraft.client.gui.recipebook.RecipeBookGui field_193018_j -public net.minecraft.util.text.CharacterManager field_238347_a_ -public net.minecraft.entity.player.PlayerInventory field_184440_g -public net.minecraft.potion.PotionBrewing field_185215_c -public net.minecraft.potion.PotionBrewing field_185214_b -public net.minecraft.potion.PotionBrewing field_185213_a -public net.minecraft.potion.PotionBrewing$MixPredicate field_185198_a -public net.minecraft.potion.PotionBrewing$MixPredicate field_185199_b -public net.minecraft.potion.PotionBrewing$MixPredicate field_185200_c -public net.minecraft.item.BucketItem field_77876_a -public net.minecraft.item.crafting.SmithingRecipe field_234838_b_ -public net.minecraft.item.crafting.SmithingRecipe field_234837_a_ -public net.minecraft.item.ItemGroup field_78034_o -public net.minecraft.nbt.CompoundNBT field_74784_a -public net.minecraft.client.gui.AbstractGui func_238461_a_(Lnet/minecraft/util/math/vector/Matrix4f;IIIIIFFFF)V -public net.minecraft.client.gui.screen.Screen func_230480_a_(Lnet/minecraft/client/gui/widget/Widget;)Lnet/minecraft/client/gui/widget/Widget; -public net.minecraft.client.gui.screen.Screen func_230481_d_(Lnet/minecraft/client/gui/IGuiEventListener;)Lnet/minecraft/client/gui/IGuiEventListener; -public net.minecraft.client.gui.screen.Screen func_231160_c_()V -public net.minecraft.client.gui.screen.Screen func_231155_a_(Ljava/lang/String;Z)V -public net.minecraft.client.gui.screen.Screen func_231154_a_(Ljava/lang/String;CI)Z \ No newline at end of file +public net.minecraft.client.gui.Font$StringRenderOutput +public net.minecraft.world.item.alchemy.PotionBrewing$Mix +public net.minecraft.client.gui.components.ImageButton f_94223_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97734_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97727_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97726_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97738_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97735_ +public net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97736_ +public net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen f_98699_ +public net.minecraft.client.gui.screens.recipebook.RecipeBookComponent f_100269_ +public net.minecraft.client.gui.screens.recipebook.RecipeBookComponent f_100281_ +public net.minecraft.client.gui.screens.recipebook.RecipeBookComponent f_100279_ +public net.minecraft.client.StringSplitter f_92333_ +public net.minecraft.nbt.CompoundTag f_128329_ +public net.minecraft.world.entity.player.Inventory f_35979_ +public net.minecraft.world.item.alchemy.PotionBrewing f_43496_ +public net.minecraft.world.item.alchemy.PotionBrewing f_43495_ +public net.minecraft.world.item.alchemy.PotionBrewing f_43494_ +public net.minecraft.world.item.alchemy.PotionBrewing$Mix f_43532_ +public net.minecraft.world.item.alchemy.PotionBrewing$Mix f_43533_ +public net.minecraft.world.item.alchemy.PotionBrewing$Mix f_43534_ +public net.minecraft.world.item.BucketItem f_40687_ +public net.minecraft.world.item.crafting.UpgradeRecipe f_44519_ +public net.minecraft.world.item.crafting.UpgradeRecipe f_44518_ +public net.minecraft.world.item.CreativeModeTab f_40763_ +public net.minecraft.client.gui.GuiComponent m_93112_(Lcom/mojang/math/Matrix4f;IIIIIFFFF)V +public net.minecraft.client.gui.screens.Screen m_7787_(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener; +public net.minecraft.client.gui.screens.Screen m_7856_()V +public net.minecraft.client.gui.screens.Screen m_6697_(Ljava/lang/String;Z)V +public net.minecraft.client.gui.screens.Screen m_96583_(Ljava/lang/String;CI)Z +public-f net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97711_ +protected net.minecraft.client.gui.screens.Screen m_6575_(Lnet/minecraft/client/Minecraft;II)V +public net.minecraft.client.gui.screens.Screen m_142416_(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener; +public net.minecraft.client.gui.screens.Screen m_169394_(Lnet/minecraft/client/gui/components/Widget;)Lnet/minecraft/client/gui/components/Widget; +public net.minecraft.client.gui.screens.Screen m_169383_(Lcom/mojang/blaze3d/vertex/PoseStack;Ljava/util/List;II)V +public net.minecraft.client.renderer.RenderType m_173209_(Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType; +public net.minecraft.client.renderer.RenderType$OutlineProperty +public net.minecraft.client.renderer.RenderType$CompositeState \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 6aebf09b4..1a89466fd 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -24,13 +24,13 @@ To allow players to view items and recipes. [[dependencies.roughlyenoughitems]] modId = "architectury" mandatory = true -versionRange = "[1.10.139,)" +versionRange = "[2.3.22,)" ordering = "NONE" side = "BOTH" [[dependencies.roughlyenoughitems]] -modId = "cloth-config" +modId = "cloth_config" mandatory = true -versionRange = "[4.11.18,)" +versionRange = "[5.0.36,)" ordering = "NONE" side = "BOTH" diff --git a/gradle.properties b/gradle.properties index a989f9f6e..dacf56056 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,14 @@ org.gradle.jvmargs=-Xmx3G base_version=6.0 unstable=true -supported_version=1.17 -minecraft_version=1.17 -forgeEnabled=false -forge_version=36.0.43 +supported_version=1.17.1 +minecraft_version=1.17.1 +forgeEnabled=true +forge_version=37.0.18 fabricloader_version=0.11.6 -cloth_config_version=5.0.34 +cloth_config_version=5.0.37 modmenu_version=2.0.2 fabric_api=0.35.2+1.17 -architectury_version=2.0.9 +architectury_version=2.3.22 api_exculde= #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric 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 628e823fc..b6dc4028d 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 @@ -28,6 +28,7 @@ import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector4f; +import dev.architectury.injectables.annotations.ExpectPlatform; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -551,35 +552,12 @@ public class ScreenOverlayImpl extends ScreenOverlay { } public void renderTooltip(PoseStack matrices, Tooltip tooltip) { - List lines = tooltip.entries().stream() - .flatMap(component -> { - if (component.isText()) { - return Minecraft.getInstance().font.getSplitter().splitLines(component.getAsText(), 100000, Style.EMPTY).stream() - .map(Language.getInstance()::getVisualOrder) - .map(ClientTooltipComponent::create); - } else { - return Stream.of(component.getAsComponent()); - } - }) - .collect(Collectors.toList()); - for (TooltipComponent component : tooltip.components()) { - 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()); + renderTooltipInner(minecraft.screen, matrices, tooltip, tooltip.getX(), tooltip.getY()); } - public void renderTooltipInner(PoseStack matrices, List lines, int mouseX, int mouseY) { - if (lines.isEmpty()) { - return; - } - matrices.pushPose(); - matrices.translate(0, 0, 500); - minecraft.screen.renderTooltipInternal(matrices, lines, mouseX, mouseY); - matrices.popPose(); + @ExpectPlatform + public static void renderTooltipInner(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY) { + throw new AssertionError(); } public void addTooltip(@Nullable Tooltip tooltip) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java index 213305e18..aed5add29 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/QueuedTooltip.java @@ -28,6 +28,7 @@ import com.google.common.collect.Lists; import me.shedaniel.math.Point; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -48,6 +49,7 @@ public class QueuedTooltip implements Tooltip { private Point location; private List entries; private List components; + private EntryStack stack = EntryStack.empty(); private QueuedTooltip(Point location, Collection entries) { this.location = location; @@ -110,6 +112,17 @@ public class QueuedTooltip implements Tooltip { Tooltip.super.queue(); } + @Override + public EntryStack getContextStack() { + return stack; + } + + @Override + public Tooltip withContextStack(EntryStack stack) { + this.stack = stack.copy(); + return this; + } + public record TooltipEntryImpl(Object obj) implements Tooltip.Entry { @Override public Component getAsText() { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java index a70f7c5d2..421422d4a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/AbstractEntryStack.java @@ -181,6 +181,7 @@ public abstract class AbstractEntryStack implements EntryStack, Renderer { try { Mutable tooltip = new MutableObject<>(getRenderer().cast().getTooltip(this, mouse)); if (tooltip.getValue() == null) return null; + tooltip.getValue().withContextStack(this); tooltip.getValue().addAllTexts(get(Settings.TOOLTIP_APPEND_EXTRA).apply(this)); tooltip.setValue(get(Settings.TOOLTIP_PROCESSOR).apply(this, tooltip.getValue())); if (tooltip.getValue() == null) return null; diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java deleted file mode 100644 index 5334fbea5..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021 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.client; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.Lifecycle; -import dev.architectury.fluid.FluidStack; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.REIRuntime; -import me.shedaniel.rei.api.client.favorites.FavoriteEntry; -import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; -import me.shedaniel.rei.api.client.gui.AbstractRenderer; -import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.drag.DraggableStackProviderWidget; -import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitorWidget; -import me.shedaniel.rei.api.client.gui.widgets.Panel; -import me.shedaniel.rei.api.client.gui.widgets.Tooltip; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.api.client.plugins.REIClientPlugin; -import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; -import me.shedaniel.rei.api.client.registry.screen.DisplayBoundsProvider; -import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; -import me.shedaniel.rei.api.client.util.ClientEntryStacks; -import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; -import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.impl.client.ClientHelperImpl; -import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; -import me.shedaniel.rei.impl.client.gui.screen.AbstractDisplayViewingScreen; -import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; -import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; -import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.function.Function; - -@Environment(EnvType.CLIENT) -@ApiStatus.Internal -public class DefaultClientRuntimePlugin implements REIClientPlugin { - @Override - public void registerEntries(EntryRegistry registry) { - if (ClientHelperImpl.getInstance().isAprilFools.get()) { - registry.addEntry(ClientEntryStacks.of(new AbstractRenderer() { - private ResourceLocation id = new ResourceLocation("roughlyenoughitems", "textures/gui/kirb.png"); - - @Override - public void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderTexture(0, id); - innerBlit(matrices.last().pose(), bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), getBlitOffset(), 0, 1, 0, 1); - } - - @Override - @Nullable - public Tooltip getTooltip(Point point) { - return Tooltip.create(new TextComponent("Kirby"), ClientHelper.getInstance().getFormattedModFromModId("Dream Land")); - } - })); - } - } - - @Override - public void registerScreens(ScreenRegistry registry) { - ExclusionZones zones = registry.exclusionZones(); - zones.register(DefaultDisplayViewingScreen.class, screen -> { - Panel widget = screen.getWorkingStationsBaseWidget(); - if (widget == null) - return Collections.emptyList(); - return Collections.singletonList(widget.getBounds().clone()); - }); - zones.register(Screen.class, screen -> { - FavoritesListWidget widget = ScreenOverlayImpl.getFavoritesListWidget(); - if (widget != null) { - if (widget.favoritePanelButton.isVisible()) { - return Collections.singletonList(widget.favoritePanelButton.bounds); - } - } - return Collections.emptyList(); - }); - registry.registerDecider(new DisplayBoundsProvider() { - @Override - public Rectangle getScreenBounds(AbstractDisplayViewingScreen screen) { - return screen.getBounds(); - } - - @Override - public boolean isHandingScreen(Class screen) { - return AbstractDisplayViewingScreen.class.isAssignableFrom(screen); - } - - @Override - public InteractionResult shouldScreenBeOverlaid(Class screen) { - return InteractionResult.SUCCESS; - } - }); - registry.registerDraggableStackProvider(DraggableStackProviderWidget.from(context -> { - if (RoughlyEnoughItemsCoreClient.shouldReturn(context.getScreen()) || !REIRuntime.getInstance().isOverlayVisible()) return Collections.emptyList(); - return Widgets.walk(REIRuntime.getInstance().getOverlay().get().children(), DraggableStackProviderWidget.class::isInstance); - })); - registry.registerDraggableStackVisitor(DraggableStackVisitorWidget.from(context -> { - if (RoughlyEnoughItemsCoreClient.shouldReturn(context.getScreen()) || !REIRuntime.getInstance().isOverlayVisible()) return Collections.emptyList(); - return Widgets.walk(REIRuntime.getInstance().getOverlay().get().children(), DraggableStackVisitorWidget.class::isInstance); - })); - } - - @Override - public void registerFavorites(FavoriteEntryType.Registry registry) { - registry.register(EntryStackFavoriteType.INSTANCE.id, EntryStackFavoriteType.INSTANCE); - } - - @Override - public void registerTransferHandlers(TransferHandlerRegistry registry) { - registry.register(new DefaultCategoryHandler()); - } - - private enum EntryStackFavoriteType implements FavoriteEntryType { - INSTANCE(FavoriteEntryType.ENTRY_STACK); - - private final String key = "data"; - private ResourceLocation id; - - EntryStackFavoriteType(ResourceLocation id) { - this.id = id; - } - - @Override - public DataResult readResult(CompoundTag object) { - EntryStack stack; - try { - stack = EntryStack.read(object.getCompound(key)); - } catch (Throwable throwable) { - return DataResult.error(throwable.getMessage()); - } - return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable()); - } - - @Override - public DataResult fromArgsResult(Object... args) { - if (args.length == 0) return DataResult.error("Cannot create EntryStackFavoriteEntry from empty args!"); - if (!(args[0] instanceof EntryStack stack)) - return DataResult.error("Creation of EntryStackFavoriteEntry from args expected EntryStack as the first argument!"); - if (!stack.supportSaving()) - return DataResult.error("Creation of EntryStackFavoriteEntry from an unserializable stack!"); - return DataResult.success(new EntryStackFavoriteEntry(stack), Lifecycle.stable()); - } - - @Override - public CompoundTag save(EntryStackFavoriteEntry entry, CompoundTag tag) { - tag.put(key, entry.stack.save()); - return tag; - } - } - - private static class EntryStackFavoriteEntry extends FavoriteEntry { - private static final Function, String> CANCEL_FLUID_AMOUNT = s -> null; - private final EntryStack stack; - private final long hash; - - public EntryStackFavoriteEntry(EntryStack stack) { - this.stack = stack.normalize(); - this.hash = EntryStacks.hashExact(this.stack); - } - - @Override - public boolean isInvalid() { - return this.stack.isEmpty(); - } - - @Override - public Renderer getRenderer(boolean showcase) { - return this.stack; - } - - @Override - public boolean doAction(int button) { - if (!ClientHelper.getInstance().isCheating()) return false; - EntryStack entry = stack.copy(); - if (!entry.isEmpty()) { - if (entry.getValueType() == FluidStack.class) { - Item bucketItem = ((FluidStack) entry.getValue()).getFluid().getBucket(); - if (bucketItem != null) { - entry = EntryStacks.of(bucketItem); - } - } - if (entry.getType() == VanillaEntryTypes.ITEM) - entry.castValue().setCount(button != 1 && !Screen.hasShiftDown() ? 1 : entry.castValue().getMaxStackSize()); - return ClientHelper.getInstance().tryCheatingEntry(entry); - } - - return false; - } - - @Override - public long hashIgnoreAmount() { - return hash; - } - - @Override - public FavoriteEntry copy() { - return new EntryStackFavoriteEntry(stack.normalize()); - } - - @Override - public ResourceLocation getType() { - return EntryStackFavoriteType.INSTANCE.id; - } - - @Override - public boolean isSame(FavoriteEntry other) { - if (!(other instanceof EntryStackFavoriteEntry that)) return false; - return EntryStacks.equalsExact(stack, that.stack); - } - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java new file mode 100644 index 000000000..22bd239b4 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java @@ -0,0 +1,252 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.client.runtime; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Lifecycle; +import dev.architectury.fluid.FluidStack; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; +import me.shedaniel.rei.api.client.ClientHelper; +import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; +import me.shedaniel.rei.api.client.gui.AbstractRenderer; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.drag.DraggableStackProviderWidget; +import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitorWidget; +import me.shedaniel.rei.api.client.gui.widgets.Panel; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; +import me.shedaniel.rei.api.client.registry.screen.DisplayBoundsProvider; +import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; +import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; +import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; +import me.shedaniel.rei.api.client.util.ClientEntryStacks; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.shedaniel.rei.impl.client.ClientHelperImpl; +import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; +import me.shedaniel.rei.impl.client.gui.screen.AbstractDisplayViewingScreen; +import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; +import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; +import me.shedaniel.rei.plugin.autocrafting.DefaultCategoryHandler; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.function.Function; + +@Environment(EnvType.CLIENT) +@ApiStatus.Internal +public class DefaultClientRuntimePlugin implements REIClientPlugin { + @Override + public void registerEntries(EntryRegistry regist