From f8e6de6909b4c9b4e725bd79e154374aeb0290f8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 15 Feb 2022 01:44:20 +0800 Subject: Support JEI API 9.3 --- .../client/gui/config/FavoriteAddWidgetMode.java | 23 ++++++++++++++++++++++ .../rei/api/client/gui/widgets/Widgets.java | 22 ++++++++++++++------- .../me/shedaniel/rei/api/client/view/Views.java | 7 +++++++ .../rei/api/common/entry/EntryIngredient.java | 6 ++++++ forge/build.gradle | 2 +- gradle.properties | 2 +- .../client/gui/widget/CatchingExceptionUtils.java | 23 ++++++++++++++++++++++ .../shedaniel/rei/impl/client/view/ViewsImpl.java | 19 ++++++++++++++++++ .../plugin/client/entry/ItemEntryDefinition.java | 1 - 9 files changed, 95 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/FavoriteAddWidgetMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/FavoriteAddWidgetMode.java index 8a846d088..ba0418920 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/FavoriteAddWidgetMode.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/FavoriteAddWidgetMode.java @@ -1,3 +1,26 @@ +/* + * 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.api.client.gui.config; import net.minecraft.client.resources.language.I18n; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index 88ab72aa5..fee50c9d5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -185,8 +185,12 @@ public final class Widgets { } public static WidgetWithBounds wrapRenderer(Rectangle bounds, Renderer renderer) { + return wrapRenderer(() -> bounds, renderer); + } + + public static WidgetWithBounds wrapRenderer(Supplier bounds, Renderer renderer) { if (renderer instanceof Widget widget) - return wrapWidgetWithBounds(widget, bounds); + return wrapWidgetWithBoundsSupplier(widget, bounds); return new RendererWrappedWidget(renderer, bounds); } @@ -195,6 +199,10 @@ public final class Widgets { } public static WidgetWithBounds wrapWidgetWithBounds(Widget widget, Rectangle bounds) { + return wrapWidgetWithBoundsSupplier(widget, bounds == null ? null : () -> bounds); + } + + public static WidgetWithBounds wrapWidgetWithBoundsSupplier(Widget widget, Supplier bounds) { if (widget instanceof WidgetWithBounds withBounds) return withBounds; if (bounds == null) @@ -204,9 +212,9 @@ public final class Widgets { private static class RendererWrappedWidget extends WidgetWithBounds { private final Renderer renderer; - private final Rectangle bounds; + private final Supplier bounds; - public RendererWrappedWidget(Renderer renderer, Rectangle bounds) { + public RendererWrappedWidget(Renderer renderer, Supplier bounds) { this.renderer = Objects.requireNonNull(renderer); this.bounds = Objects.requireNonNull(bounds); } @@ -235,21 +243,21 @@ public final class Widgets { @Override public Rectangle getBounds() { - return bounds; + return bounds.get(); } } private static class DelegateWidgetWithBounds extends DelegateWidget { - private final Rectangle bounds; + private final Supplier bounds; - public DelegateWidgetWithBounds(Widget widget, Rectangle bounds) { + public DelegateWidgetWithBounds(Widget widget, Supplier bounds) { super(widget); this.bounds = bounds; } @Override public Rectangle getBounds() { - return bounds; + return bounds.get(); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java index cb426d6c1..0baa9d3d4 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java @@ -27,6 +27,8 @@ import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.Reloadable; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -35,6 +37,11 @@ public interface Views extends Reloadable { return PluginManager.getClientInstance().get(Views.class); } + @Nullable + @ApiStatus.Internal + @ApiStatus.Experimental + ViewSearchBuilder getContext(); + /** * Returns all craftable items from materials. * diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java index 5f5e48bda..efdc401df 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java @@ -31,6 +31,8 @@ import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Predicate; import java.util.function.UnaryOperator; +import java.util.stream.Collector; +import java.util.stream.Collectors; /** * An immutable representation of a list of {@link EntryStack}. @@ -71,6 +73,10 @@ public interface EntryIngredient extends List> { return Internals.getEntryIngredientProvider().of(stacks); } + static Collector, ?, EntryIngredient> collector() { + return Collectors.collectingAndThen(Collectors.toList(), EntryIngredient::of); + } + ListTag save(); @SuppressWarnings("rawtypes") diff --git a/forge/build.gradle b/forge/build.gradle index ff7bf5841..169443d01 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -95,7 +95,7 @@ dependencies { modRuntime("curse.maven:refined-storage-243076:3623324") modRuntime("appeng:appliedenergistics2:10.0.1") // modRuntime("curse.maven:tcon-74072:3273213") - // modRuntime("curse.maven:mantle-74924:3273201") + modRuntime("curse.maven:mantle-74924:3634761") modRuntime("curse.maven:jer-240630:3575590") modRuntime("curse.maven:jep-417645:3550303") modRuntime("curse.maven:simple-storage-network-268495:3594529") diff --git a/gradle.properties b/gradle.properties index f3ae45d1e..769402ba0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ unstable=false supported_version=1.18.x minecraft_version=1.18.1 forgeEnabled=true -forge_version=39.0.5 +forge_version=39.0.76 fabricloader_version=0.12.12 cloth_config_version=6.2.57 modmenu_version=3.0.0 diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CatchingExceptionUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CatchingExceptionUtils.java index 1015160f8..74b5e220a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CatchingExceptionUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CatchingExceptionUtils.java @@ -1,3 +1,26 @@ +/* + * 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.widget; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java index c07a29072..df371c961 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java @@ -56,6 +56,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Consumer; @@ -64,7 +65,25 @@ import java.util.stream.Stream; @ApiStatus.Internal public class ViewsImpl implements Views { + private static final ThreadLocal BUILDER = new ThreadLocal<>(); + + @Nullable + @Override + public ViewSearchBuilder getContext() { + return BUILDER.get(); + } + public static Map, List> buildMapFor(ViewSearchBuilder builder) { + BUILDER.set(builder); + + try { + return _buildMapFor(builder); + } finally { + BUILDER.remove(); + } + } + + private static Map, List> _buildMapFor(ViewSearchBuilder builder) { if (PluginManager.areAnyReloading()) { RoughlyEnoughItemsCore.LOGGER.info("Cancelled Views buildMap since plugins have not finished reloading."); return Maps.newLinkedHashMap(); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java index 62ec927db..1515ed6ae 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/ItemEntryDefinition.java @@ -298,7 +298,6 @@ public class ItemEntryDefinition implements EntryDefinition, EntrySer Minecraft.getInstance().getItemRenderer().render(value, ItemTransforms.TransformType.GUI, false, matrices, immediate, ITEM_LIGHT, OverlayTexture.NO_OVERLAY, model); matrices.popPose(); - throw new AssertionError(); /*ItemStack value = entry.getValue(); matrices.pushPose(); -- cgit