Skip to content

Commit

Permalink
Add a method for creating clickable ingredients with the ingredient m…
Browse files Browse the repository at this point in the history
…anager
  • Loading branch information
mezz committed Sep 19, 2024
1 parent 9e68684 commit 05ef020
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -160,6 +161,22 @@ default <V> Optional<ITypedIngredient<V>> createTypedIngredient(V ingredient) {
*/
<V> ITypedIngredient<V> normalizeTypedIngredient(ITypedIngredient<V> 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
*/
<V> Optional<IClickableIngredient<V>> createClickableIngredient(IIngredientType<V> 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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,6 +203,18 @@ public <V> ITypedIngredient<V> normalizeTypedIngredient(ITypedIngredient<V> type
return TypedIngredient.normalize(typedIngredient, ingredientHelper);
}

@Override
public <V> Optional<IClickableIngredient<V>> createClickableIngredient(IIngredientType<V> 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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ
jUnitVersion=5.8.2

# Version
specificationVersion=19.18.4
specificationVersion=19.18.5

0 comments on commit 05ef020

Please sign in to comment.