Skip to content

Commit 05ef020

Browse files
committed
Add a method for creating clickable ingredients with the ingredient manager
1 parent 9e68684 commit 05ef020

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

CommonApi/src/main/java/mezz/jei/api/runtime/IClickableIngredient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* This can be an ingredient drawn in a GUI container slot, a fluid tank,
1111
* or anything else that holds ingredients.
1212
*
13+
* Create one with {@link IIngredientManager#createClickableIngredient}.
14+
*
1315
* @since 11.5.0
1416
*/
1517
public interface IClickableIngredient<T> {

CommonApi/src/main/java/mezz/jei/api/runtime/IIngredientManager.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import mezz.jei.api.ingredients.subtypes.UidContext;
1414
import mezz.jei.api.registration.IExtraIngredientRegistration;
1515
import mezz.jei.api.registration.IIngredientAliasRegistration;
16+
import net.minecraft.client.renderer.Rect2i;
1617
import net.minecraft.world.item.ItemStack;
1718
import org.jetbrains.annotations.Unmodifiable;
1819

@@ -160,6 +161,22 @@ default <V> Optional<ITypedIngredient<V>> createTypedIngredient(V ingredient) {
160161
*/
161162
<V> ITypedIngredient<V> normalizeTypedIngredient(ITypedIngredient<V> typedIngredient);
162163

164+
/**
165+
* Create a clickable ingredient.
166+
*
167+
* @see IClickableIngredient
168+
*
169+
* @param ingredientType the type of the ingredient being clicked
170+
* @param ingredient the ingredient being clicked
171+
* @param area the area that this clickable ingredient is drawn in, in absolute screen coordinates.
172+
* @param normalize set true to normalize the ingredient (see {@link IIngredientHelper#normalizeIngredient}
173+
*
174+
* @return a clickable ingredient, or {@link Optional#empty()} if the ingredient is invalid (see {@link IIngredientHelper#isValidIngredient}
175+
*
176+
* @since 19.18.5
177+
*/
178+
<V> Optional<IClickableIngredient<V>> createClickableIngredient(IIngredientType<V> ingredientType, V ingredient, Rect2i area, boolean normalize);
179+
163180
/**
164181
* Get an ingredient by the given unique id.
165182
* This uses the uids from {@link IIngredientHelper#getUniqueId(Object, UidContext)}

Library/src/main/java/mezz/jei/library/ingredients/IngredientManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import mezz.jei.api.ingredients.IIngredientType;
77
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
88
import mezz.jei.api.ingredients.ITypedIngredient;
9+
import mezz.jei.api.runtime.IClickableIngredient;
910
import mezz.jei.api.runtime.IIngredientManager;
11+
import mezz.jei.common.input.ClickableIngredient;
1012
import mezz.jei.common.util.ErrorUtil;
13+
import mezz.jei.common.util.ImmutableRect2i;
1114
import mezz.jei.common.util.Translator;
1215
import mezz.jei.core.util.WeakList;
16+
import net.minecraft.client.renderer.Rect2i;
1317
import net.minecraft.resources.ResourceLocation;
1418
import org.apache.logging.log4j.LogManager;
1519
import org.apache.logging.log4j.Logger;
@@ -199,6 +203,18 @@ public <V> ITypedIngredient<V> normalizeTypedIngredient(ITypedIngredient<V> type
199203
return TypedIngredient.normalize(typedIngredient, ingredientHelper);
200204
}
201205

206+
@Override
207+
public <V> Optional<IClickableIngredient<V>> createClickableIngredient(IIngredientType<V> ingredientType, V ingredient, Rect2i area, boolean normalize) {
208+
ErrorUtil.checkNotNull(ingredientType, "ingredientType");
209+
ErrorUtil.checkNotNull(ingredient, "ingredient");
210+
ErrorUtil.checkNotNull(area, "area");
211+
return TypedIngredient.createAndFilterInvalid(this, ingredientType, ingredient, normalize)
212+
.map(typedIngredient -> {
213+
ImmutableRect2i slotArea = new ImmutableRect2i(area);
214+
return new ClickableIngredient<>(typedIngredient, slotArea);
215+
});
216+
}
217+
202218
@SuppressWarnings("removal")
203219
@Override
204220
@Deprecated

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
7474
jUnitVersion=5.8.2
7575

7676
# Version
77-
specificationVersion=19.18.4
77+
specificationVersion=19.18.5

0 commit comments

Comments
 (0)