diff --git a/CommonApi/src/main/java/mezz/jei/api/runtime/IClickableIngredient.java b/CommonApi/src/main/java/mezz/jei/api/runtime/IClickableIngredient.java index 6fdab6c10..4c69d4377 100644 --- a/CommonApi/src/main/java/mezz/jei/api/runtime/IClickableIngredient.java +++ b/CommonApi/src/main/java/mezz/jei/api/runtime/IClickableIngredient.java @@ -10,6 +10,8 @@ * This can be an ingredient drawn in a GUI container slot, a fluid tank, * or anything else that holds ingredients. * + * Create one with {@link IIngredientManager#createClickableIngredient}. + * * @since 11.5.0 */ public interface IClickableIngredient { diff --git a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java index d58fe9ab6..0af6b79a3 100644 --- a/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java +++ b/CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java @@ -13,6 +13,7 @@ import mezz.jei.api.ingredients.subtypes.UidContext; import mezz.jei.api.registration.IExtraIngredientRegistration; import mezz.jei.api.registration.IIngredientAliasRegistration; +import net.minecraft.client.renderer.Rect2i; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Unmodifiable; @@ -160,6 +161,22 @@ default Optional> createTypedIngredient(V ingredient) { */ ITypedIngredient normalizeTypedIngredient(ITypedIngredient typedIngredient); + /** + * Create a clickable ingredient. + * + * @see IClickableIngredient + * + * @param ingredientType the type of the ingredient being clicked + * @param ingredient the ingredient being clicked + * @param area the area that this clickable ingredient is drawn in, in absolute screen coordinates. + * @param normalize set true to normalize the ingredient (see {@link IIngredientHelper#normalizeIngredient} + * + * @return a clickable ingredient, or {@link Optional#empty()} if the ingredient is invalid (see {@link IIngredientHelper#isValidIngredient} + * + * @since 19.18.5 + */ + Optional> createClickableIngredient(IIngredientType ingredientType, V ingredient, Rect2i area, boolean normalize); + /** * Get an ingredient by the given unique id. * This uses the uids from {@link IIngredientHelper#getUniqueId(Object, UidContext)} diff --git a/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java b/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java index 726227d5a..0f20f3403 100644 --- a/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java +++ b/Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java @@ -6,10 +6,14 @@ import mezz.jei.api.ingredients.IIngredientType; import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes; import mezz.jei.api.ingredients.ITypedIngredient; +import mezz.jei.api.runtime.IClickableIngredient; import mezz.jei.api.runtime.IIngredientManager; +import mezz.jei.common.input.ClickableIngredient; import mezz.jei.common.util.ErrorUtil; +import mezz.jei.common.util.ImmutableRect2i; import mezz.jei.common.util.Translator; import mezz.jei.core.util.WeakList; +import net.minecraft.client.renderer.Rect2i; import net.minecraft.resources.ResourceLocation; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -199,6 +203,18 @@ public ITypedIngredient normalizeTypedIngredient(ITypedIngredient type return TypedIngredient.normalize(typedIngredient, ingredientHelper); } + @Override + public Optional> createClickableIngredient(IIngredientType ingredientType, V ingredient, Rect2i area, boolean normalize) { + ErrorUtil.checkNotNull(ingredientType, "ingredientType"); + ErrorUtil.checkNotNull(ingredient, "ingredient"); + ErrorUtil.checkNotNull(area, "area"); + return TypedIngredient.createAndFilterInvalid(this, ingredientType, ingredient, normalize) + .map(typedIngredient -> { + ImmutableRect2i slotArea = new ImmutableRect2i(area); + return new ClickableIngredient<>(typedIngredient, slotArea); + }); + } + @SuppressWarnings("removal") @Override @Deprecated diff --git a/gradle.properties b/gradle.properties index f71ed44fb..6f3003e32 100644 --- a/gradle.properties +++ b/gradle.properties @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ jUnitVersion=5.8.2 # Version -specificationVersion=19.18.4 +specificationVersion=19.18.5