Skip to content

Commit

Permalink
Add some convenience functions for accepting default ItemLike and Flu…
Browse files Browse the repository at this point in the history
…id ingredients
  • Loading branch information
mezz committed Sep 13, 2024
1 parent d20b43e commit f67c265
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -102,11 +103,32 @@ default THIS addItemStack(ItemStack itemStack) {
return addIngredient(VanillaTypes.ITEM_STACK, itemStack);
}

/**
* Convenience function to add one {@link ItemLike}.
*
* @since 19.18.1
*/
default IIngredientConsumer addItemLike(ItemLike itemLike) {
return addItemStack(new ItemStack(itemLike));
}

/**
* Convenience helper to add one Fluid ingredient with the default amount (one bucket).
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with an amount.
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
* @since 19.18.1
*/
THIS addFluidStack(Fluid fluid);

/**
* Convenience helper to add one Fluid ingredient.
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
* @since 11.1.0
*/
Expand All @@ -117,6 +139,7 @@ default THIS addItemStack(ItemStack itemStack) {
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
* @see #addFluidStack(Fluid, long) to add a Fluid without a {@link DataComponentPatch}.
* @since 18.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.material.Fluid;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -104,11 +105,32 @@ default IIngredientConsumer addItemStack(ItemStack itemStack) {
return addIngredient(VanillaTypes.ITEM_STACK, itemStack);
}

/**
* Convenience function to add one {@link ItemLike}.
*
* @since 19.18.1
*/
default IIngredientConsumer addItemLike(ItemLike itemLike) {
return addItemStack(new ItemStack(itemLike));
}

/**
* Convenience helper to add one Fluid ingredient with the default amount (one bucket).
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with an amount.
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
* @since 19.18.1
*/
IIngredientConsumer addFluidStack(Fluid fluid);

/**
* Convenience helper to add one Fluid ingredient.
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
* @since 19.8.3
*/
Expand All @@ -119,6 +141,7 @@ default IIngredientConsumer addItemStack(ItemStack itemStack) {
*
* To add multiple Fluid ingredients, you can call this multiple times.
*
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
* @see #addFluidStack(Fluid, long) to add a Fluid without a {@link DataComponentPatch}.
* @since 19.8.3
*/
Expand Down
12 changes: 12 additions & 0 deletions CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;

/**
* Helps with the implementation of GUIs.
Expand Down Expand Up @@ -71,6 +72,17 @@ default IDrawable createDrawableItemStack(ItemStack ingredient) {
return createDrawableIngredient(VanillaTypes.ITEM_STACK, ingredient);
}

/**
* Returns a 16x16 drawable for the given ItemLike,
* matching the one JEI draws in the ingredient list.
*
* @see #createDrawableIngredient(IIngredientType, Object) for other ingredient types.
* @since 19.18.1
*/
default IDrawable createDrawableItemLike(ItemLike itemLike) {
return createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(itemLike));
}

/**
* Returns a 16x16 drawable for the given ingredient,
* matching the one JEI draws in the ingredient list.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mezz.jei.library.gui.recipes.layout.builder;

import mezz.jei.api.gui.builder.IIngredientAcceptor;
import mezz.jei.api.gui.builder.IIngredientConsumer;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.ITypedIngredient;
import net.minecraft.core.component.DataComponentPatch;
Expand Down Expand Up @@ -40,6 +41,11 @@ public IngredientAcceptorVoid addOptionalTypedIngredients(List<Optional<ITypedIn
return this;
}

@Override
public IngredientAcceptorVoid addFluidStack(Fluid fluid) {
return this;
}

@Override
public IngredientAcceptorVoid addFluidStack(Fluid fluid, long amount) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.IntSet;
import mezz.jei.api.gui.builder.IIngredientConsumer;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable;
Expand Down Expand Up @@ -62,6 +63,12 @@ public <I> IRecipeSlotBuilder addIngredient(IIngredientType<I> ingredientType, I
return this;
}

@Override
public IRecipeSlotBuilder addFluidStack(Fluid fluid) {
this.ingredients.addFluidStack(fluid);
return this;
}

@Override
public IRecipeSlotBuilder addFluidStack(Fluid fluid, long amount) {
this.ingredients.addFluidStack(fluid, amount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mezz.jei.library.gui.recipes.supplier.builder;

import mezz.jei.api.gui.builder.IIngredientConsumer;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
Expand Down Expand Up @@ -39,6 +40,12 @@ public <I> IRecipeSlotBuilder addIngredient(IIngredientType<I> ingredientType, I
return this;
}

@Override
public IRecipeSlotBuilder addFluidStack(Fluid fluid) {
this.ingredients.addFluidStack(fluid);
return this;
}

@Override
public IRecipeSlotBuilder addFluidStack(Fluid fluid, long amount) {
this.ingredients.addFluidStack(fluid, amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import mezz.jei.api.gui.builder.IIngredientAcceptor;
import mezz.jei.api.gui.builder.IIngredientConsumer;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
Expand Down Expand Up @@ -87,6 +88,13 @@ public <I> DisplayIngredientAcceptor addTypedIngredient(ITypedIngredient<I> type
return this;
}

@SuppressWarnings("deprecation")
@Override
public DisplayIngredientAcceptor addFluidStack(Fluid fluid) {
IPlatformFluidHelperInternal<?> fluidHelper = Services.PLATFORM.getFluidHelper();
return addFluidInternal(fluidHelper, fluid.builtInRegistryHolder(), fluidHelper.bucketVolume(), DataComponentPatch.EMPTY);
}

@SuppressWarnings("deprecation")
@Override
public DisplayIngredientAcceptor addFluidStack(Fluid fluid, long amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import mezz.jei.api.gui.builder.IIngredientAcceptor;
import mezz.jei.api.gui.builder.IIngredientConsumer;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
import mezz.jei.api.ingredients.ITypedIngredient;
Expand Down Expand Up @@ -84,6 +85,13 @@ public <I> SimpleIngredientAcceptor addTypedIngredient(ITypedIngredient<I> typed
return this;
}

@SuppressWarnings("deprecation")
@Override
public SimpleIngredientAcceptor addFluidStack(Fluid fluid) {
IPlatformFluidHelperInternal<?> fluidHelper = Services.PLATFORM.getFluidHelper();
return addFluidInternal(fluidHelper, fluid.builtInRegistryHolder(), fluidHelper.bucketVolume(), DataComponentPatch.EMPTY);
}

@SuppressWarnings("deprecation")
@Override
public SimpleIngredientAcceptor addFluidStack(Fluid fluid, long amount) {
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.0
specificationVersion=19.18.1

0 comments on commit f67c265

Please sign in to comment.