diff --git a/Common/src/main/java/mezz/jei/common/gui/elements/OffsetDrawable.java b/Common/src/main/java/mezz/jei/common/gui/elements/OffsetDrawable.java index b34372894..fdb1648cc 100644 --- a/Common/src/main/java/mezz/jei/common/gui/elements/OffsetDrawable.java +++ b/Common/src/main/java/mezz/jei/common/gui/elements/OffsetDrawable.java @@ -2,6 +2,7 @@ import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.placement.IPlaceable; +import mezz.jei.common.util.ImmutableRect2i; import net.minecraft.client.gui.GuiGraphics; /** @@ -55,4 +56,8 @@ public OffsetDrawable setPosition(int xPos, int yPos) { this.yOffset = yPos; return this; } + + public ImmutableRect2i getArea() { + return new ImmutableRect2i(xOffset, yOffset, getWidth(), getHeight()); + } } diff --git a/Common/src/main/java/mezz/jei/common/util/ImmutablePoint2i.java b/Common/src/main/java/mezz/jei/common/util/ImmutablePoint2i.java index 6f217dff9..ab6850993 100644 --- a/Common/src/main/java/mezz/jei/common/util/ImmutablePoint2i.java +++ b/Common/src/main/java/mezz/jei/common/util/ImmutablePoint2i.java @@ -1,3 +1,5 @@ package mezz.jei.common.util; -public record ImmutablePoint2i(int x, int y) {} +public record ImmutablePoint2i(int x, int y) { + public static final ImmutablePoint2i ORIGIN = new ImmutablePoint2i(0, 0); +} diff --git a/Common/src/main/java/mezz/jei/common/util/MathUtil.java b/Common/src/main/java/mezz/jei/common/util/MathUtil.java index c9bb96504..a2d739af4 100644 --- a/Common/src/main/java/mezz/jei/common/util/MathUtil.java +++ b/Common/src/main/java/mezz/jei/common/util/MathUtil.java @@ -112,9 +112,9 @@ public static double distance(Vec2 start, Vec2 end) { * Illegal matrix math assumes the pose is only scaling and translation. * If we get rotating GUI elements we're doomed, I hope nobody wants those. */ - public static ScreenRectangle transform(ScreenRectangle rect, Matrix4f pose) { - Vector3f topLeft = new Vector3f(rect.left(), rect.top(), 1.0f); - Vector3f bottomRight = new Vector3f(rect.right(), rect.bottom(), 1.0f); + public static ScreenRectangle transform(ImmutableRect2i rect, Matrix4f pose) { + Vector3f topLeft = new Vector3f(rect.x(), rect.y(), 1.0f); + Vector3f bottomRight = new Vector3f(rect.x() + rect.width(), rect.y() + rect.getHeight(), 1.0f); topLeft = pose.transformPosition(topLeft); bottomRight = pose.transformPosition(bottomRight); diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/builder/IRecipeLayoutBuilder.java b/CommonApi/src/main/java/mezz/jei/api/gui/builder/IRecipeLayoutBuilder.java index d5cebc577..fe0afec84 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/builder/IRecipeLayoutBuilder.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/builder/IRecipeLayoutBuilder.java @@ -1,7 +1,7 @@ package mezz.jei.api.gui.builder; import mezz.jei.api.gui.placement.IPlaceable; -import mezz.jei.api.gui.widgets.ISlottedWidgetFactory; +import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.recipe.category.IRecipeCategory; @@ -29,6 +29,18 @@ default IRecipeSlotBuilder addInputSlot(int x, int y) { .setPosition(x, y); } + /** + * Convenience function to add an input slot. + * Set its position using {@link IPlaceable} methods on {@link IRecipeSlotBuilder}. + * + * @return a {@link IRecipeSlotBuilder} that has further methods for adding ingredients, setting position, etc. + * + * @since 19.19.3 + */ + default IRecipeSlotBuilder addInputSlot() { + return addSlot(RecipeIngredientRole.INPUT); + } + /** * Convenience function to add an output slot that will be drawn at the given position relative to the recipe layout. * @@ -43,6 +55,18 @@ default IRecipeSlotBuilder addOutputSlot(int x, int y) { .setPosition(x, y); } + /** + * Convenience function to add an output slot. + * Set its position using {@link IPlaceable} methods on {@link IRecipeSlotBuilder}. + * + * @return a {@link IRecipeSlotBuilder} that has further methods for adding ingredients, setting position, etc. + * + * @since 19.19.3 + */ + default IRecipeSlotBuilder addOutputSlot() { + return addSlot(RecipeIngredientRole.OUTPUT); + } + /** * Add a slot that will be drawn at the given position relative to the recipe layout. * @@ -59,7 +83,7 @@ default IRecipeSlotBuilder addSlot(RecipeIngredientRole role, int x, int y) { } /** - * Add a slot and set its position using {@link IPlaceable} methods. + * Add a slot and set its position using {@link IPlaceable} methods on {@link IRecipeSlotBuilder}. * * @param role the {@link RecipeIngredientRole} of this slot (for lookups). * @return a {@link IRecipeSlotBuilder} that has further methods for adding ingredients, etc. @@ -69,14 +93,17 @@ default IRecipeSlotBuilder addSlot(RecipeIngredientRole role, int x, int y) { IRecipeSlotBuilder addSlot(RecipeIngredientRole role); /** - * Assign this slot to a {@link ISlottedWidgetFactory}, + * Assign this slot to a {@link mezz.jei.api.gui.widgets.ISlottedWidgetFactory}, * so that the widget can manage this slot instead the recipe category. * - * @param widgetFactory the {@link ISlottedWidgetFactory} to assign this slot to. + * @param widgetFactory the {@link mezz.jei.api.gui.widgets.ISlottedWidgetFactory} to assign this slot to. * * @since 19.7.0 + * @deprecated there are easier ways to create slotted widgets now. Use {@link IRecipeExtrasBuilder#addSlottedWidget}. */ - IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, ISlottedWidgetFactory widgetFactory); + @Deprecated(since = "19.19.3", forRemoval = true) + @SuppressWarnings("removal") + IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, mezz.jei.api.gui.widgets.ISlottedWidgetFactory widgetFactory); /** * Add ingredients that are important for recipe lookup, but are not displayed on the recipe layout. diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawable.java b/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawable.java index 5743145ab..cdb97d0d0 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawable.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawable.java @@ -107,4 +107,12 @@ public interface IRecipeSlotDrawable extends IRecipeSlotView { default void addTooltipCallback(IRecipeSlotTooltipCallback tooltipCallback) { } + + /** + * Get the area that this recipe slot draws on, including the area covered by its background texture. + * Useful for laying out other recipe elements relative to the slot. + * + * @since 19.19.3 + */ + Rect2i getAreaIncludingBackground(); } diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawablesView.java b/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawablesView.java new file mode 100644 index 000000000..c7ebbd590 --- /dev/null +++ b/CommonApi/src/main/java/mezz/jei/api/gui/ingredient/IRecipeSlotDrawablesView.java @@ -0,0 +1,58 @@ +package mezz.jei.api.gui.ingredient; + +import mezz.jei.api.gui.builder.IRecipeSlotBuilder; +import mezz.jei.api.recipe.RecipeIngredientRole; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * Represents all the drawn ingredients in slots that are part of a recipe. + * + * This view is meant as a source of information for drawing, positioning, and tooltips. + * + * @see IRecipeSlotsView for a view with less access to drawable properties of the slots. + * + * @since 19.19.3 + */ +public interface IRecipeSlotDrawablesView { + /** + * Get all slots for a recipe. + * + * @since 19.19.3 + */ + @Unmodifiable + List getSlots(); + + /** + * Get the list of slots for the given {@link RecipeIngredientRole} for a recipe. + * + * @since 19.19.3 + */ + default List getSlots(RecipeIngredientRole role) { + List list = new ArrayList<>(); + for (IRecipeSlotDrawable slotView : getSlots()) { + if (slotView.getRole() == role) { + list.add(slotView); + } + } + return list; + } + + /** + * Get a recipe slot by its name set with {@link IRecipeSlotBuilder#setSlotName(String)}. + * + * @since 19.19.3 + */ + default Optional findSlotByName(String slotName) { + return getSlots().stream() + .filter(slot -> + slot.getSlotName() + .map(slotName::equals) + .orElse(false) + ) + .findFirst(); + } +} diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IRecipeExtrasBuilder.java b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IRecipeExtrasBuilder.java index dbe7a4326..029ee8745 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IRecipeExtrasBuilder.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IRecipeExtrasBuilder.java @@ -1,6 +1,8 @@ package mezz.jei.api.gui.widgets; import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawablesView; import mezz.jei.api.gui.inputs.IJeiGuiEventListener; import mezz.jei.api.gui.inputs.IJeiInputHandler; import mezz.jei.api.gui.placement.IPlaceable; @@ -26,8 +28,16 @@ * @since 19.6.0 */ public interface IRecipeExtrasBuilder { + + /** + * Get the recipe slots that were created in {@link IRecipeCategory#setRecipe}. + * + * @since 19.19.3 + */ + IRecipeSlotDrawablesView getRecipeSlots(); + /** - * Add a {@link IDrawable} for the recipe category. + * Add a {@link IDrawable} for the recipe category at the given position. * * @since 19.19.0 */ @@ -47,6 +57,14 @@ public interface IRecipeExtrasBuilder { */ void addWidget(IRecipeWidget widget); + /** + * Add a {@link ISlottedRecipeWidget} for the recipe category, and + * mark that the slots are going to be handled by the slotted widget. + * + * @since 19.19.3 + */ + void addSlottedWidget(ISlottedRecipeWidget widget, List slots); + /** * Add a {@link IJeiInputHandler} for the recipe category. * @@ -71,6 +89,18 @@ public interface IRecipeExtrasBuilder { */ IScrollBoxWidget addScrollBoxWidget(int width, int height, int xPos, int yPos); + /** + * Create and add a new scroll grid widget. + * Handles displaying ingredients in a scrolling area with a scrollbar, similar to the vanilla creative menu. + * + * Get slots for this from {@link #getRecipeSlots()}. + * + * You can move the resulting grid by using the {@link IScrollGridWidget}'s {@link IPlaceable} methods. + * + * @since 19.19.3 + */ + IScrollGridWidget addScrollGridWidget(List slots, int columns, int visibleRows); + /** * Add a vanilla-style recipe arrow to the recipe layout. * diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidget.java b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidget.java new file mode 100644 index 000000000..e0f259eb9 --- /dev/null +++ b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidget.java @@ -0,0 +1,20 @@ +package mezz.jei.api.gui.widgets; + +import mezz.jei.api.gui.placement.IPlaceable; +import net.minecraft.client.gui.navigation.ScreenRectangle; + +/** + * A scrolling area for ingredients with a scrollbar. + * Modeled after the vanilla creative menu. + * + * Create one with {@link IRecipeExtrasBuilder#addScrollGridWidget}. + * @since 19.19.3 + */ +public interface IScrollGridWidget extends ISlottedRecipeWidget, IPlaceable { + /** + * Get the position and size of this widget, relative to its parent element. + * + * @since 19.19.3 + */ + ScreenRectangle getScreenRectangle(); +} diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidgetFactory.java b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidgetFactory.java index 792391e06..58a7938ae 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidgetFactory.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/IScrollGridWidgetFactory.java @@ -9,7 +9,10 @@ * Get an instance from {@link IGuiHelper#createScrollGridFactory(int, int)} * * @since 19.7.0 + * @deprecated use {@link IRecipeExtrasBuilder#addScrollGridWidget} instead, it's much simpler */ +@SuppressWarnings({"DeprecatedIsStillUsed", "removal"}) +@Deprecated(since = "19.19.3", forRemoval = true) public interface IScrollGridWidgetFactory extends ISlottedWidgetFactory { /** * @since 19.7.0 diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedRecipeWidget.java b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedRecipeWidget.java index 29e265754..03c2b85bc 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedRecipeWidget.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedRecipeWidget.java @@ -1,20 +1,15 @@ package mezz.jei.api.gui.widgets; -import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; import mezz.jei.api.gui.inputs.RecipeSlotUnderMouse; -import mezz.jei.api.recipe.category.IRecipeCategory; +import java.util.List; import java.util.Optional; /** * Like {@link IRecipeWidget}, but it also manages {@link IRecipeSlotDrawable}s. * - * These must be created by an {@link ISlottedWidgetFactory}. - * Pass the factory to {@link IRecipeLayoutBuilder#addSlotToWidget} - * when creating slots in {@link IRecipeCategory#setRecipe} - * - * Once the slots are built, the factory will be called to create your complete {@link ISlottedRecipeWidget}. + * Add one to a recipe category by using {@link IRecipeExtrasBuilder#addSlottedWidget(ISlottedRecipeWidget, List)} * * @since 19.7.0 */ diff --git a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedWidgetFactory.java b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedWidgetFactory.java index 8bb3eb5a2..a4c4f4d6e 100644 --- a/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedWidgetFactory.java +++ b/CommonApi/src/main/java/mezz/jei/api/gui/widgets/ISlottedWidgetFactory.java @@ -13,7 +13,10 @@ * and then JEI will call {@link #createWidgetForSlots} after all the slots are built. * * @since 19.7.0 + * @deprecated there are easier ways to create slotted widgets now. Use {@link IRecipeExtrasBuilder#addSlottedWidget}. */ +@SuppressWarnings({"DeprecatedIsStillUsed", "removal"}) +@Deprecated(since = "19.19.3", forRemoval = true) @FunctionalInterface public interface ISlottedWidgetFactory { /** @@ -26,5 +29,7 @@ public interface ISlottedWidgetFactory { * * @since 19.7.0 */ + @Deprecated(since = "19.19.3", forRemoval = true) + @SuppressWarnings("removal") void createWidgetForSlots(IRecipeExtrasBuilder builder, R recipe, List slots); } diff --git a/CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java b/CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java index 8069eb36f..04d5a9ad5 100644 --- a/CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java +++ b/CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java @@ -11,8 +11,6 @@ import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.gui.widgets.IRecipeWidget; import mezz.jei.api.gui.widgets.IScrollBoxWidget; -import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory; -import mezz.jei.api.gui.widgets.ISlottedWidgetFactory; import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.recipe.RecipeIngredientRole; @@ -176,11 +174,14 @@ default IDrawable createDrawableItemLike(ItemLike itemLike) { * Create a scroll grid widget factory. * Handles displaying a grid of ingredient slots in a scrolling area. * - * Add ingredients to it using {@link IRecipeLayoutBuilder#addSlotToWidget(RecipeIngredientRole, ISlottedWidgetFactory)} + * Add ingredients to it using {@link IRecipeLayoutBuilder#addSlotToWidget(RecipeIngredientRole, mezz.jei.api.gui.widgets.ISlottedWidgetFactory)} * * @since 19.7.0 + * @deprecated use {@link IRecipeExtrasBuilder#addScrollGridWidget} instead, it's much simpler */ - IScrollGridWidgetFactory createScrollGridFactory(int columns, int visibleRows); + @SuppressWarnings("removal") + @Deprecated(since = "19.19.3", forRemoval = true) + mezz.jei.api.gui.widgets.IScrollGridWidgetFactory createScrollGridFactory(int columns, int visibleRows); /** * Create a scroll box widget. diff --git a/CommonApi/src/main/java/mezz/jei/api/recipe/category/IRecipeCategory.java b/CommonApi/src/main/java/mezz/jei/api/recipe/category/IRecipeCategory.java index 55b338307..e98c9db13 100644 --- a/CommonApi/src/main/java/mezz/jei/api/recipe/category/IRecipeCategory.java +++ b/CommonApi/src/main/java/mezz/jei/api/recipe/category/IRecipeCategory.java @@ -26,6 +26,7 @@ import net.minecraft.world.item.crafting.RecipeHolder; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; /** @@ -119,9 +120,11 @@ default int getHeight() { * information more easily than from the recipe category directly. * * @since 19.19.0 + * @deprecated use {@link #createRecipeExtras(IRecipeExtrasBuilder, Object, IFocusGroup)}, the recipe slots are in {@link IRecipeExtrasBuilder#getRecipeSlots()} now. */ + @Deprecated(since = "19.19.3", forRemoval = true) default void createRecipeExtras(IRecipeExtrasBuilder builder, T recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { - createRecipeExtras(builder, recipe, focuses); + } /** @@ -132,11 +135,10 @@ default void createRecipeExtras(IRecipeExtrasBuilder builder, T recipe, IRecipeS * information more easily than from the recipe category directly. * * @since 19.6.0 - * @deprecated use {@link #createRecipeExtras(IRecipeExtrasBuilder, Object, IRecipeSlotsView, IFocusGroup)} */ - @Deprecated(since = "19.19.0", forRemoval = true) + @SuppressWarnings("RedundantUnmodifiable") default void createRecipeExtras(IRecipeExtrasBuilder builder, T recipe, IFocusGroup focuses) { - + createRecipeExtras(builder, recipe, () -> Collections.unmodifiableList(builder.getRecipeSlots().getSlots()), focuses); } /** diff --git a/CommonApi/src/main/java/mezz/jei/api/recipe/category/extensions/IRecipeCategoryExtension.java b/CommonApi/src/main/java/mezz/jei/api/recipe/category/extensions/IRecipeCategoryExtension.java index 5176e4051..8db66fd75 100644 --- a/CommonApi/src/main/java/mezz/jei/api/recipe/category/extensions/IRecipeCategoryExtension.java +++ b/CommonApi/src/main/java/mezz/jei/api/recipe/category/extensions/IRecipeCategoryExtension.java @@ -85,9 +85,11 @@ default List getTooltipStrings(T recipe, double mouseX, double mouseY * information more easily than from the recipe category directly. * * @since 19.19.0 + * @deprecated use {@link #createRecipeExtras(Object, IRecipeExtrasBuilder, ICraftingGridHelper, IFocusGroup)}, the recipe slots are in {@link IRecipeExtrasBuilder#getRecipeSlots()} now. */ + @Deprecated(since = "19.19.3", forRemoval = true) default void createRecipeExtras(T recipe, IRecipeExtrasBuilder builder, IRecipeSlotsView recipeSlotsView, ICraftingGridHelper craftingGridHelper, IFocusGroup focuses) { - createRecipeExtras(recipe, builder, craftingGridHelper, focuses); + } /** @@ -98,11 +100,10 @@ default void createRecipeExtras(T recipe, IRecipeExtrasBuilder builder, IRecipeS * information more easily than from the recipe category directly. * * @since 19.6.0 - * @deprecated use {@link #createRecipeExtras(Object, IRecipeExtrasBuilder, IRecipeSlotsView, ICraftingGridHelper, IFocusGroup)} */ - @Deprecated(since = "19.19.0", forRemoval = true) + @SuppressWarnings("RedundantUnmodifiable") default void createRecipeExtras(T recipe, IRecipeExtrasBuilder builder, ICraftingGridHelper craftingGridHelper, IFocusGroup focuses) { - + createRecipeExtras(recipe, builder, () -> Collections.unmodifiableList(builder.getRecipeSlots().getSlots()), craftingGridHelper, focuses); } /** diff --git a/Library/src/main/java/mezz/jei/library/gui/helpers/GuiHelper.java b/Library/src/main/java/mezz/jei/library/gui/helpers/GuiHelper.java index aca7b1066..7e3ff3f94 100644 --- a/Library/src/main/java/mezz/jei/library/gui/helpers/GuiHelper.java +++ b/Library/src/main/java/mezz/jei/library/gui/helpers/GuiHelper.java @@ -8,7 +8,6 @@ import mezz.jei.api.gui.ingredient.ICraftingGridHelper; import mezz.jei.api.gui.widgets.IRecipeWidget; import mezz.jei.api.gui.widgets.IScrollBoxWidget; -import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.ingredients.IIngredientRenderer; import mezz.jei.api.ingredients.IIngredientType; @@ -146,9 +145,10 @@ public ICraftingGridHelper createCraftingGridHelper() { return CraftingGridHelper.INSTANCE; } + @SuppressWarnings("removal") @Override - public IScrollGridWidgetFactory createScrollGridFactory(int columns, int visibleRows) { - return new ScrollGridWidgetFactory<>(this, columns, visibleRows); + public mezz.jei.api.gui.widgets.IScrollGridWidgetFactory createScrollGridFactory(int columns, int visibleRows) { + return new ScrollGridWidgetFactory<>(columns, visibleRows); } @SuppressWarnings("removal") diff --git a/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java b/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java index b4740a5bd..13ef07baa 100644 --- a/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java +++ b/Library/src/main/java/mezz/jei/library/gui/ingredients/RecipeSlot.java @@ -18,9 +18,11 @@ import mezz.jei.common.Internal; import mezz.jei.common.config.IClientConfig; import mezz.jei.common.gui.JeiTooltip; +import mezz.jei.common.gui.elements.OffsetDrawable; import mezz.jei.common.platform.IPlatformRenderHelper; import mezz.jei.common.platform.Services; import mezz.jei.common.util.ImmutableRect2i; +import mezz.jei.common.util.MathUtil; import mezz.jei.common.util.SafeIngredientUtil; import mezz.jei.library.gui.recipes.layout.builder.LegacyTooltipCallbackAdapter; import mezz.jei.library.ingredients.DisplayIngredientAcceptor; @@ -44,7 +46,7 @@ public class RecipeSlot implements IRecipeSlotView, IRecipeSlotDrawable { private final ICycler cycler; private final List tooltipCallbacks; private final @Nullable RendererOverrides rendererOverrides; - private final @Nullable IDrawable background; + private final @Nullable OffsetDrawable background; private final @Nullable IDrawable overlay; private final @Nullable String slotName; private ImmutableRect2i rect; @@ -74,7 +76,7 @@ public RecipeSlot( List tooltipCallbacks, List>> allIngredients, @Nullable List>> focusedIngredients, - @Nullable IDrawable background, + @Nullable OffsetDrawable background, @Nullable IDrawable overlay, @Nullable String slotName, @Nullable RendererOverrides rendererOverrides @@ -353,6 +355,14 @@ public Rect2i getRect() { return rect.toMutable(); } + @Override + public Rect2i getAreaIncludingBackground() { + if (background == null) { + return rect.toMutable(); + } + return MathUtil.union(rect, background.getArea()).toMutable(); + } + @Override public String toString() { return "RecipeSlot{" + diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/RecipeLayout.java b/Library/src/main/java/mezz/jei/library/gui/recipes/RecipeLayout.java index e78363d6c..b3ccb5cd3 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/RecipeLayout.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/RecipeLayout.java @@ -7,6 +7,7 @@ import mezz.jei.api.gui.drawable.IDrawableStatic; import mezz.jei.api.gui.drawable.IScalableDrawable; import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawablesView; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.gui.inputs.IJeiGuiEventListener; import mezz.jei.api.gui.inputs.IJeiInputHandler; @@ -15,6 +16,7 @@ import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; import mezz.jei.api.gui.widgets.IRecipeWidget; import mezz.jei.api.gui.widgets.IScrollBoxWidget; +import mezz.jei.api.gui.widgets.IScrollGridWidget; import mezz.jei.api.gui.widgets.ISlottedRecipeWidget; import mezz.jei.api.gui.widgets.ITextWidget; import mezz.jei.api.ingredients.IIngredientType; @@ -36,6 +38,7 @@ import mezz.jei.library.gui.ingredients.CycleTicker; import mezz.jei.library.gui.recipes.layout.builder.RecipeLayoutBuilder; import mezz.jei.library.gui.widgets.ScrollBoxRecipeWidget; +import mezz.jei.library.gui.widgets.ScrollGridRecipeWidget; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.navigation.ScreenPosition; import net.minecraft.client.renderer.Rect2i; @@ -62,7 +65,6 @@ public class RecipeLayout implements IRecipeLayoutDrawable, IRecipeExtrasB /** * Slots handled by the recipe category directly. */ - @Unmodifiable private final List recipeCategorySlots; /** * All slots, including slots handled by the recipe category and widgets. @@ -120,7 +122,7 @@ public static Optional> create( recipeBackground, recipeBorderPadding ); - recipeCategory.createRecipeExtras(recipeLayout, recipe, recipeLayout.getRecipeSlotsView(), focuses); + recipeCategory.createRecipeExtras(recipeLayout, recipe, focuses); return Optional.of(recipeLayout); } catch (RuntimeException | LinkageError e) { LOGGER.error("Error caught from Recipe Category: {}", recipeCategory.getRecipeType(), e); @@ -171,7 +173,7 @@ public RecipeLayout( this.recipeBackground = recipeBackground; this.shapelessIcon = shapelessIcon; - recipeCategory.onDisplayedIngredientsUpdate(recipe, recipeCategorySlots, focuses); + recipeCategory.onDisplayedIngredientsUpdate(recipe, Collections.unmodifiableList(recipeCategorySlots), focuses); } @Override @@ -377,6 +379,11 @@ public IRecipeSlotsView getRecipeSlotsView() { return () -> Collections.unmodifiableList(allSlots); } + @Override + public IRecipeSlotDrawablesView getRecipeSlots() { + return () -> Collections.unmodifiableList(recipeCategorySlots); + } + @Override public R getRecipe() { return recipe; @@ -420,6 +427,13 @@ public void addWidget(IRecipeWidget widget) { } } + @Override + public void addSlottedWidget(ISlottedRecipeWidget widget, List slots) { + this.allWidgets.add(widget); + this.slottedWidgets.add(widget); + this.recipeCategorySlots.removeAll(slots); + } + @Override public void addInputHandler(IJeiInputHandler inputHandler) { this.inputHandler.addInputHandler(inputHandler); @@ -438,6 +452,14 @@ public IScrollBoxWidget addScrollBoxWidget(int width, int height, int xPos, int return widget; } + @Override + public IScrollGridWidget addScrollGridWidget(List slots, int columns, int visibleRows) { + ScrollGridRecipeWidget widget = ScrollGridRecipeWidget.create(slots, columns, visibleRows); + addSlottedWidget(widget, slots); + addInputHandler(widget); + return widget; + } + @Override public IPlaceable addRecipeArrow() { Textures textures = Internal.getTextures(); diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java index b24b2885b..6ee8106ed 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeLayoutBuilder.java @@ -8,7 +8,6 @@ import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.drawable.IScalableDrawable; import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; -import mezz.jei.api.gui.widgets.ISlottedWidgetFactory; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.recipe.IFocusGroup; import mezz.jei.api.recipe.RecipeIngredientRole; @@ -38,8 +37,8 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; -// TODO: make IRecipeLayoutBuilder take a generic parameter for ISlottedWidgetFactory public class RecipeLayoutBuilder implements IRecipeLayoutBuilder { private final List slots = new ArrayList<>(); private final List> focusLinkedSlots = new ArrayList<>(); @@ -73,8 +72,10 @@ public IRecipeSlotBuilder addSlot(RecipeIngredientRole role) { return slot; } + @SuppressWarnings("removal") @Override - public IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, ISlottedWidgetFactory widgetFactory) { + @Deprecated + public IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, mezz.jei.api.gui.widgets.ISlottedWidgetFactory widgetFactory) { RecipeSlotBuilder slot = new RecipeSlotBuilder(ingredientManager, nextSlotIndex++, role) .assignToWidgetFactory(widgetFactory); @@ -152,6 +153,7 @@ public void createFocusLink(IIngredientAcceptor... slots) { this.focusLinkedSlots.add(builders); } + @SuppressWarnings("removal") public RecipeLayout buildRecipeLayout( IFocusGroup focuses, Collection> decorators, @@ -163,7 +165,7 @@ public RecipeLayout buildRecipeLayout( List> recipeCategorySlots = new ArrayList<>(); List> allSlots = new ArrayList<>(); - ListMultiMap, Pair> widgetSlots = new ListMultiMap<>(); + ListMultiMap, Pair> widgetSlots = new ListMultiMap<>(); CycleTicker cycleTicker = CycleTicker.createWithRandomOffset(); @@ -174,7 +176,7 @@ public RecipeLayout buildRecipeLayout( focusMatches.addAll(slot.getMatches(focuses)); } for (RecipeSlotBuilder slotBuilder : linkedSlots) { - ISlottedWidgetFactory assignedWidget = slotBuilder.getAssignedWidget(); + mezz.jei.api.gui.widgets.ISlottedWidgetFactory assignedWidget = slotBuilder.getAssignedWidget(); Pair slotDrawable = slotBuilder.build(focusMatches, cycleTicker); if (assignedWidget == null) { recipeCategorySlots.add(slotDrawable); @@ -188,7 +190,7 @@ public RecipeLayout buildRecipeLayout( for (RecipeSlotBuilder slotBuilder : slots) { if (!focusLinkedSlots.contains(slotBuilder)) { - ISlottedWidgetFactory assignedWidget = slotBuilder.getAssignedWidget(); + mezz.jei.api.gui.widgets.ISlottedWidgetFactory assignedWidget = slotBuilder.getAssignedWidget(); Pair slotDrawable = slotBuilder.build(focuses, cycleTicker); if (assignedWidget == null) { recipeCategorySlots.add(slotDrawable); @@ -213,10 +215,10 @@ public RecipeLayout buildRecipeLayout( focuses ); - for (Map.Entry, List>> e : widgetSlots.entrySet()) { + for (Map.Entry, List>> e : widgetSlots.entrySet()) { // TODO: breaking change: add a type parameter to IRecipeLayoutBuilder to avoid this cast @SuppressWarnings("unchecked") - ISlottedWidgetFactory factory = (ISlottedWidgetFactory) e.getKey(); + mezz.jei.api.gui.widgets.ISlottedWidgetFactory factory = (mezz.jei.api.gui.widgets.ISlottedWidgetFactory) e.getKey(); List slots = sortSlots(e.getValue()); factory.createWidgetForSlots(recipeLayout, recipe, slots); } @@ -228,7 +230,7 @@ private static List sortSlots(List assignedWidgetFactory; + @SuppressWarnings("removal") + private @Nullable mezz.jei.api.gui.widgets.ISlottedWidgetFactory assignedWidgetFactory; public RecipeSlotBuilder(IIngredientManager ingredientManager, int slotIndex, RecipeIngredientRole role) { this.ingredients = new DisplayIngredientAcceptor(ingredientManager); @@ -108,7 +107,7 @@ public IRecipeSlotBuilder addOptionalTypedIngredients(List widgetFactory) { + @SuppressWarnings("removal") + public RecipeSlotBuilder assignToWidgetFactory(mezz.jei.api.gui.widgets.ISlottedWidgetFactory widgetFactory) { ErrorUtil.checkNotNull(widgetFactory, "widgetFactory"); this.assignedWidgetFactory = widgetFactory; return this; } + @SuppressWarnings("removal") @Nullable - public ISlottedWidgetFactory getAssignedWidget() { + public mezz.jei.api.gui.widgets.ISlottedWidgetFactory getAssignedWidget() { return assignedWidgetFactory; } diff --git a/Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSupplierBuilder.java b/Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSupplierBuilder.java index 0a8622b31..84c820c07 100644 --- a/Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSupplierBuilder.java +++ b/Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSupplierBuilder.java @@ -3,7 +3,6 @@ import mezz.jei.api.gui.builder.IIngredientAcceptor; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.builder.IRecipeSlotBuilder; -import mezz.jei.api.gui.widgets.ISlottedWidgetFactory; import mezz.jei.api.recipe.RecipeIngredientRole; import mezz.jei.api.runtime.IIngredientManager; import mezz.jei.library.gui.recipes.RecipeLayoutIngredientSupplier; @@ -27,12 +26,7 @@ public IngredientSupplierBuilder(IIngredientManager ingredientManager) { @Override public IRecipeSlotBuilder addSlot(RecipeIngredientRole role, int x, int y) { - IngredientSlotBuilder slot = ingredientSlotBuilders.get(role); - if (slot == null) { - slot = new IngredientSlotBuilder(ingredientManager); - ingredientSlotBuilders.put(role, slot); - } - return slot; + return addSlot(role); } @Override @@ -45,14 +39,15 @@ public IRecipeSlotBuilder addSlot(RecipeIngredientRole role) { return slot; } + @SuppressWarnings("removal") @Override - public IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, ISlottedWidgetFactory widgetFactory) { - return addSlot(role, 0, 0); + public IRecipeSlotBuilder addSlotToWidget(RecipeIngredientRole role, mezz.jei.api.gui.widgets.ISlottedWidgetFactory widgetFactory) { + return addSlot(role); } @Override public IIngredientAcceptor addInvisibleIngredients(RecipeIngredientRole role) { - return addSlot(role, 0, 0); + return addSlot(role); } @Override diff --git a/Library/src/main/java/mezz/jei/library/gui/widgets/AbstractScrollWidget.java b/Library/src/main/java/mezz/jei/library/gui/widgets/AbstractScrollWidget.java index 48a3e2d7c..a4f2b268b 100644 --- a/Library/src/main/java/mezz/jei/library/gui/widgets/AbstractScrollWidget.java +++ b/Library/src/main/java/mezz/jei/library/gui/widgets/AbstractScrollWidget.java @@ -31,8 +31,8 @@ protected static ImmutableRect2i calculateScrollArea(int width, int height) { ); } - protected final ScreenRectangle area; - protected final ScreenRectangle contentsArea; + protected ImmutableRect2i area; + protected final ImmutableRect2i contentsArea; private final ImmutableRect2i scrollArea; private final DrawableNineSliceTexture scrollbarMarker; @@ -46,13 +46,13 @@ protected static ImmutableRect2i calculateScrollArea(int width, int height) { */ private float scrollOffsetY = 0; - public AbstractScrollWidget(ScreenRectangle area) { + public AbstractScrollWidget(ImmutableRect2i area) { this.area = area; this.scrollArea = calculateScrollArea(area.width(), area.height()); Textures textures = Internal.getTextures(); this.scrollbarMarker = textures.getScrollbarMarker(); this.scrollbarBackground = textures.getScrollbarBackground(); - this.contentsArea = new ScreenRectangle( + this.contentsArea = new ImmutableRect2i( 0, 0, area.width() - getScrollBoxScrollbarExtraWidth(), @@ -84,12 +84,12 @@ protected float getScrollOffsetY() { @Override public final ScreenRectangle getArea() { - return area; + return area.toScreenRectangle(); } @Override public final ScreenPosition getPosition() { - return area.position(); + return area.getScreenPosition(); } @Override diff --git a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollBoxRecipeWidget.java b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollBoxRecipeWidget.java index 8aa65faa3..7b129f39f 100644 --- a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollBoxRecipeWidget.java +++ b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollBoxRecipeWidget.java @@ -9,6 +9,7 @@ import mezz.jei.common.config.IJeiClientConfigs; import mezz.jei.common.gui.elements.DrawableBlank; import mezz.jei.common.gui.elements.DrawableWrappedText; +import mezz.jei.common.util.ImmutableRect2i; import mezz.jei.common.util.MathUtil; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.navigation.ScreenRectangle; @@ -21,7 +22,7 @@ public class ScrollBoxRecipeWidget extends AbstractScrollWidget implements IScro private IDrawable contents = DrawableBlank.EMPTY; public ScrollBoxRecipeWidget(int width, int height, int xPos, int yPos) { - super(new ScreenRectangle(xPos, yPos, width, height)); + super(new ImmutableRect2i(xPos, yPos, width, height)); } @Override diff --git a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridRecipeWidget.java b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridRecipeWidget.java index 7f26b9777..6ff8dff42 100644 --- a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridRecipeWidget.java +++ b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridRecipeWidget.java @@ -4,8 +4,10 @@ import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; import mezz.jei.api.gui.inputs.IJeiInputHandler; import mezz.jei.api.gui.inputs.RecipeSlotUnderMouse; +import mezz.jei.api.gui.widgets.IScrollGridWidget; import mezz.jei.api.gui.widgets.ISlottedRecipeWidget; -import mezz.jei.api.helpers.IGuiHelper; +import mezz.jei.common.Internal; +import mezz.jei.common.util.ImmutableRect2i; import mezz.jei.common.util.ImmutableSize2i; import mezz.jei.common.util.MathUtil; import net.minecraft.client.gui.GuiGraphics; @@ -14,24 +16,31 @@ import java.util.List; import java.util.Optional; -public class ScrollGridRecipeWidget extends AbstractScrollWidget implements ISlottedRecipeWidget, IJeiInputHandler { +public class ScrollGridRecipeWidget extends AbstractScrollWidget implements IScrollGridWidget, ISlottedRecipeWidget, IJeiInputHandler { private final IDrawable slotBackground; private final int columns; private final int visibleRows; private final int hiddenRows; private final List slots; - public static ImmutableSize2i calculateSize(IDrawable slotBackground, int columns, int visibleRows) { + public static ImmutableSize2i calculateSize(int columns, int visibleRows) { + IDrawable slotBackground = Internal.getTextures().getSlot(); return new ImmutableSize2i( columns * slotBackground.getWidth() + getScrollBoxScrollbarExtraWidth(), visibleRows * slotBackground.getHeight() ); } - public ScrollGridRecipeWidget(IGuiHelper guiHelper, ScreenRectangle area, int columns, int visibleRows, List slots) { + public static ScrollGridRecipeWidget create(List slots, int columns, int visibleRows) { + ImmutableSize2i size = calculateSize(columns, visibleRows); + ImmutableRect2i area = new ImmutableRect2i(0, 0, size.width(), size.height()); + return new ScrollGridRecipeWidget(area, columns, visibleRows, slots); + } + + public ScrollGridRecipeWidget(ImmutableRect2i area, int columns, int visibleRows, List slots) { super(area); this.slots = slots; - this.slotBackground = guiHelper.getSlotDrawable(); + this.slotBackground = Internal.getTextures().getSlot(); this.columns = columns; this.visibleRows = visibleRows; @@ -39,6 +48,27 @@ public ScrollGridRecipeWidget(IGuiHelper guiHelper, ScreenRectangle area, int co this.hiddenRows = Math.max(totalRows - visibleRows, 0); } + @Override + public ScrollGridRecipeWidget setPosition(int xPos, int yPos) { + this.area = area.setPosition(xPos, yPos); + return this; + } + + @Override + public int getWidth() { + return area.width(); + } + + @Override + public int getHeight() { + return area.height(); + } + + @Override + public ScreenRectangle getScreenRectangle() { + return area.toScreenRectangle(); + } + @Override protected int getVisibleAmount() { return visibleRows; diff --git a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridWidgetFactory.java b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridWidgetFactory.java index 330017c4a..944808068 100644 --- a/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridWidgetFactory.java +++ b/Library/src/main/java/mezz/jei/library/gui/widgets/ScrollGridWidgetFactory.java @@ -1,45 +1,41 @@ package mezz.jei.library.gui.widgets; -import mezz.jei.api.gui.drawable.IDrawableStatic; import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; -import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory; -import mezz.jei.api.helpers.IGuiHelper; +import mezz.jei.common.util.ImmutablePoint2i; import mezz.jei.common.util.ImmutableSize2i; import net.minecraft.client.gui.navigation.ScreenRectangle; import java.util.List; -public class ScrollGridWidgetFactory implements IScrollGridWidgetFactory { +@SuppressWarnings("removal") +public class ScrollGridWidgetFactory implements mezz.jei.api.gui.widgets.IScrollGridWidgetFactory { private final int columns; private final int visibleRows; - private final IGuiHelper guiHelper; - private ScreenRectangle area; - - public ScrollGridWidgetFactory(IGuiHelper guiHelper, int columns, int visibleRows) { - this.guiHelper = guiHelper; - IDrawableStatic slotBackground = guiHelper.getSlotDrawable(); + private ImmutablePoint2i position; + public ScrollGridWidgetFactory(int columns, int visibleRows) { this.columns = columns; this.visibleRows = visibleRows; - ImmutableSize2i size = ScrollGridRecipeWidget.calculateSize(slotBackground, columns, visibleRows); - this.area = new ScreenRectangle(0, 0, size.width(), size.height()); + this.position = ImmutablePoint2i.ORIGIN; } @Override public void setPosition(int x, int y) { - area = new ScreenRectangle(x, y, area.width(), area.height()); + position = new ImmutablePoint2i(x, y); } @Override public ScreenRectangle getArea() { - return area; + ImmutableSize2i size = ScrollGridRecipeWidget.calculateSize(columns, visibleRows); + return new ScreenRectangle(position.x(), position.y(), size.width(), size.height()); } @Override public void createWidgetForSlots(IRecipeExtrasBuilder builder, R recipe, List slots) { - ScrollGridRecipeWidget widget = new ScrollGridRecipeWidget(guiHelper, area, columns, visibleRows, slots); - builder.addWidget(widget); + ScrollGridRecipeWidget widget = ScrollGridRecipeWidget.create(slots, columns, visibleRows); + widget.setPosition(position.x(), position.y()); + builder.addSlottedWidget(widget, slots); builder.addInputHandler(widget); } } diff --git a/Library/src/main/java/mezz/jei/library/plugins/debug/DebugRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/debug/DebugRecipeCategory.java index d0955d261..48d9d8b0a 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/debug/DebugRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/debug/DebugRecipeCategory.java @@ -188,7 +188,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, DebugRecipe recipe, IFocusGr } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, DebugRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, DebugRecipe recipe, IFocusGroup focuses) { builder.addInputHandler(new JeiInputHandler(recipe, new ScreenRectangle(0, 0, RECIPE_WIDTH, RECIPE_HEIGHT))); } diff --git a/Library/src/main/java/mezz/jei/library/plugins/jei/info/IngredientInfoRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/jei/info/IngredientInfoRecipeCategory.java index 7ded49772..67bd93904 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/jei/info/IngredientInfoRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/jei/info/IngredientInfoRecipeCategory.java @@ -46,7 +46,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiIngredientInfoRecipe rec } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiIngredientInfoRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiIngredientInfoRecipe recipe, IFocusGroup focuses) { int yPos = 22; int height = recipeHeight - yPos; builder.addScrollBoxWidget( diff --git a/Library/src/main/java/mezz/jei/library/plugins/jei/tags/TagInfoRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/jei/tags/TagInfoRecipeCategory.java index ecb686d2b..6d1065afc 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/jei/tags/TagInfoRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/jei/tags/TagInfoRecipeCategory.java @@ -1,11 +1,12 @@ package mezz.jei.library.plugins.jei.tags; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawablesView; import mezz.jei.api.gui.placement.HorizontalAlignment; import mezz.jei.api.gui.placement.VerticalAlignment; import mezz.jei.api.gui.widgets.IRecipeExtrasBuilder; -import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory; +import mezz.jei.api.gui.widgets.IScrollGridWidget; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.ingredients.ITypedIngredient; import mezz.jei.api.recipe.IFocusGroup; @@ -16,7 +17,6 @@ import mezz.jei.common.platform.Services; import mezz.jei.library.util.ResourceLocationUtil; import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; @@ -31,8 +31,6 @@ public class TagInfoRecipeCategory scrollGridFactory; - public TagInfoRecipeCategory(IGuiHelper guiHelper, T recipeType, ResourceLocation registryLocation) { super( recipeType, @@ -41,13 +39,6 @@ public TagInfoRecipeCategory(IGuiHelper guiHelper, T recipeType, ResourceLocatio WIDTH, HEIGHT ); - - this.scrollGridFactory = guiHelper.createScrollGridFactory(7, 5); - ScreenRectangle gridArea = this.scrollGridFactory.getArea(); - this.scrollGridFactory.setPosition( - (WIDTH - gridArea.width()) / 2, - 20 - ); } private static Component createTitle(ResourceLocation registryLocation) { @@ -64,19 +55,18 @@ private static Component createTitle(ResourceLocation registryLocation) { @Override public void setRecipe(IRecipeLayoutBuilder builder, R recipe, IFocusGroup focuses) { - ScreenRectangle gridArea = scrollGridFactory.getArea(); - builder.addInputSlot(gridArea.position().x() + 1, 1) + builder.addInputSlot() .addTypedIngredients(recipe.getTypedIngredients()) .setStandardSlotBackground(); for (ITypedIngredient stack : recipe.getTypedIngredients()) { - builder.addSlotToWidget(RecipeIngredientRole.OUTPUT, scrollGridFactory) + builder.addOutputSlot() .addTypedIngredient(stack); } } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, R recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, R recipe, IFocusGroup focuses) { TagKey tag = recipe.getTag(); IPlatformRenderHelper renderHelper = Services.PLATFORM.getRenderHelper(); @@ -91,6 +81,16 @@ public void createRecipeExtras(IRecipeExtrasBuilder builder, R recipe, IRecipeSl .setLineSpacing(0) .setTextAlignment(VerticalAlignment.CENTER) .setTextAlignment(HorizontalAlignment.CENTER); + + IRecipeSlotDrawablesView recipeSlots = builder.getRecipeSlots(); + List outputSlots = recipeSlots.getSlots(RecipeIngredientRole.OUTPUT); + + IScrollGridWidget scrollGridWidget = builder.addScrollGridWidget(outputSlots, 7, 5); + scrollGridWidget.setPosition(0, 0, getWidth(), getHeight(), HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM); + + IRecipeSlotDrawable inputSlot = recipeSlots.getSlots(RecipeIngredientRole.INPUT) + .getFirst(); + inputSlot.setPosition(scrollGridWidget.getScreenRectangle().position().x() + 1, 1); } @Override diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/AnvilRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/AnvilRecipeCategory.java index 64a382b31..8ea1016d5 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/AnvilRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/AnvilRecipeCategory.java @@ -3,6 +3,7 @@ import mezz.jei.api.constants.RecipeTypes; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; import mezz.jei.api.gui.builder.IRecipeSlotBuilder; +import mezz.jei.api.gui.ingredient.IRecipeSlotDrawablesView; import mezz.jei.api.gui.ingredient.IRecipeSlotView; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.gui.placement.HorizontalAlignment; @@ -68,11 +69,11 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiAnvilRecipe recipe, IFoc } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiAnvilRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiAnvilRecipe recipe, IFocusGroup focuses) { builder.addRecipePlusSign().setPosition(27, 3); builder.addRecipeArrow().setPosition(76, 1); - Integer cost = getCost(recipeSlotsView); + Integer cost = getCost(builder.getRecipeSlots()); if (cost != null) { String costText = cost < 0 ? "err" : Integer.toString(cost); Component text = Component.translatable("container.repair.cost", costText); @@ -90,7 +91,7 @@ public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiAnvilRecipe rec } } - private @Nullable Integer getCost(IRecipeSlotsView recipeSlotsView) { + private @Nullable Integer getCost(IRecipeSlotDrawablesView recipeSlotsView) { Optional leftStack = recipeSlotsView.findSlotByName(leftSlotName) .flatMap(IRecipeSlotView::getDisplayedItemStack); diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/SmithingRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/SmithingRecipeCategory.java index 10c7f0c8e..9dcc97cbc 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/SmithingRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/anvil/SmithingRecipeCategory.java @@ -88,7 +88,7 @@ public void onDisplayedIngredientsUpdate(RecipeHolder recipeHold } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipe, IFocusGroup focuses) { builder.addRecipeArrow().setPosition(61, 6); } diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/brewing/BrewingRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/brewing/BrewingRecipeCategory.java index 283854444..9064605b4 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/brewing/BrewingRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/brewing/BrewingRecipeCategory.java @@ -57,7 +57,7 @@ public void draw(IJeiBrewingRecipe recipe, IRecipeSlotsView recipeSlotsView, Gui } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiBrewingRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiBrewingRecipe recipe, IFocusGroup focuses) { int brewingSteps = recipe.getBrewingSteps(); String brewingStepsString = brewingSteps < Integer.MAX_VALUE ? Integer.toString(brewingSteps) : "?"; Component steps = Component.translatable("gui.jei.category.brewing.steps", brewingStepsString); diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/compostable/CompostableRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/compostable/CompostableRecipeCategory.java index c75718e16..d76d61bc0 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/compostable/CompostableRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/compostable/CompostableRecipeCategory.java @@ -33,7 +33,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiCompostingRecipe recipe, } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiCompostingRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiCompostingRecipe recipe, IFocusGroup focuses) { float chance = recipe.getChance(); int chancePercent = (int) Math.floor(chance * 100); Component text = Component.translatable("gui.jei.category.compostable.chance", chancePercent); diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/AbstractCookingCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/AbstractCookingCategory.java index 569150d95..8fd8bc9a7 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/AbstractCookingCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/AbstractCookingCategory.java @@ -55,7 +55,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipeHolder, IFocusGroup focuses) { T recipe = recipeHolder.value(); int cookTime = recipe.getCookingTime(); if (cookTime <= 0) { diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/CampfireCookingCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/CampfireCookingCategory.java index 3d902b6ec..dc0a86e71 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/CampfireCookingCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/CampfireCookingCategory.java @@ -29,7 +29,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipeHolder, IFocusGroup focuses) { CampfireCookingRecipe recipe = recipeHolder.value(); int cookTime = recipe.getCookingTime(); if (cookTime <= 0) { diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/fuel/FurnaceFuelCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/fuel/FurnaceFuelCategory.java index b25d8e873..c93f68d32 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/fuel/FurnaceFuelCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/cooking/fuel/FurnaceFuelCategory.java @@ -47,7 +47,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiFuelingRecipe recipe, IF } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiFuelingRecipe recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, IJeiFuelingRecipe recipe, IFocusGroup focuses) { int burnTime = recipe.getBurnTime(); builder.addAnimatedRecipeFlame(burnTime) .setPosition(1, 0); diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/crafting/CraftingRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/crafting/CraftingRecipeCategory.java index 60182a3b8..e18cabd20 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/crafting/CraftingRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/crafting/CraftingRecipeCategory.java @@ -62,9 +62,9 @@ public void onDisplayedIngredientsUpdate(RecipeHolder recipeHold } @Override - public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipeHolder, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipeHolder, IFocusGroup focuses) { var recipeExtension = this.extendableHelper.getRecipeExtension(recipeHolder); - recipeExtension.createRecipeExtras(recipeHolder, builder, recipeSlotsView, craftingGridHelper, focuses); + recipeExtension.createRecipeExtras(recipeHolder, builder, craftingGridHelper, focuses); } @Override diff --git a/Library/src/main/java/mezz/jei/library/plugins/vanilla/stonecutting/StoneCuttingRecipeCategory.java b/Library/src/main/java/mezz/jei/library/plugins/vanilla/stonecutting/StoneCuttingRecipeCategory.java index ed7900919..316bce77d 100644 --- a/Library/src/main/java/mezz/jei/library/plugins/vanilla/stonecutting/StoneCuttingRecipeCategory.java +++ b/Library/src/main/java/mezz/jei/library/plugins/vanilla/stonecutting/StoneCuttingRecipeCategory.java @@ -45,7 +45,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, RecipeHolder recipe, IRecipeSlotsView recipeSlotsView, IFocusGroup focuses) { + public void createRecipeExtras(IRecipeExtrasBuilder builder, RecipeHolder recipe, IFocusGroup focuses) { builder.addRecipeArrow().setPosition(26, 9); } diff --git a/gradle.properties b/gradle.properties index 8ab54d60a..248159d7d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ jUnitVersion=5.8.2 # Version -specificationVersion=19.19.2 +specificationVersion=19.19.3