Skip to content

Commit f67c265

Browse files
committed
Add some convenience functions for accepting default ItemLike and Fluid ingredients
1 parent d20b43e commit f67c265

File tree

9 files changed

+95
-1
lines changed

9 files changed

+95
-1
lines changed

CommonApi/src/main/java/mezz/jei/api/gui/builder/IIngredientAcceptor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.core.component.DataComponentPatch;
77
import net.minecraft.world.item.ItemStack;
88
import net.minecraft.world.item.crafting.Ingredient;
9+
import net.minecraft.world.level.ItemLike;
910
import net.minecraft.world.level.material.Fluid;
1011
import org.jetbrains.annotations.ApiStatus;
1112
import org.jetbrains.annotations.Nullable;
@@ -102,11 +103,32 @@ default THIS addItemStack(ItemStack itemStack) {
102103
return addIngredient(VanillaTypes.ITEM_STACK, itemStack);
103104
}
104105

106+
/**
107+
* Convenience function to add one {@link ItemLike}.
108+
*
109+
* @since 19.18.1
110+
*/
111+
default IIngredientConsumer addItemLike(ItemLike itemLike) {
112+
return addItemStack(new ItemStack(itemLike));
113+
}
114+
115+
/**
116+
* Convenience helper to add one Fluid ingredient with the default amount (one bucket).
117+
*
118+
* To add multiple Fluid ingredients, you can call this multiple times.
119+
*
120+
* @see #addFluidStack(Fluid, long) to add a Fluid with an amount.
121+
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
122+
* @since 19.18.1
123+
*/
124+
THIS addFluidStack(Fluid fluid);
125+
105126
/**
106127
* Convenience helper to add one Fluid ingredient.
107128
*
108129
* To add multiple Fluid ingredients, you can call this multiple times.
109130
*
131+
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
110132
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
111133
* @since 11.1.0
112134
*/
@@ -117,6 +139,7 @@ default THIS addItemStack(ItemStack itemStack) {
117139
*
118140
* To add multiple Fluid ingredients, you can call this multiple times.
119141
*
142+
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
120143
* @see #addFluidStack(Fluid, long) to add a Fluid without a {@link DataComponentPatch}.
121144
* @since 18.0.0
122145
*/

CommonApi/src/main/java/mezz/jei/api/gui/builder/IIngredientConsumer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.core.component.DataComponentPatch;
77
import net.minecraft.world.item.ItemStack;
88
import net.minecraft.world.item.crafting.Ingredient;
9+
import net.minecraft.world.level.ItemLike;
910
import net.minecraft.world.level.material.Fluid;
1011
import org.jetbrains.annotations.ApiStatus;
1112
import org.jetbrains.annotations.Nullable;
@@ -104,11 +105,32 @@ default IIngredientConsumer addItemStack(ItemStack itemStack) {
104105
return addIngredient(VanillaTypes.ITEM_STACK, itemStack);
105106
}
106107

108+
/**
109+
* Convenience function to add one {@link ItemLike}.
110+
*
111+
* @since 19.18.1
112+
*/
113+
default IIngredientConsumer addItemLike(ItemLike itemLike) {
114+
return addItemStack(new ItemStack(itemLike));
115+
}
116+
117+
/**
118+
* Convenience helper to add one Fluid ingredient with the default amount (one bucket).
119+
*
120+
* To add multiple Fluid ingredients, you can call this multiple times.
121+
*
122+
* @see #addFluidStack(Fluid, long) to add a Fluid with an amount.
123+
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
124+
* @since 19.18.1
125+
*/
126+
IIngredientConsumer addFluidStack(Fluid fluid);
127+
107128
/**
108129
* Convenience helper to add one Fluid ingredient.
109130
*
110131
* To add multiple Fluid ingredients, you can call this multiple times.
111132
*
133+
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
112134
* @see #addFluidStack(Fluid, long, DataComponentPatch) to add a Fluid with a {@link DataComponentPatch}.
113135
* @since 19.8.3
114136
*/
@@ -119,6 +141,7 @@ default IIngredientConsumer addItemStack(ItemStack itemStack) {
119141
*
120142
* To add multiple Fluid ingredients, you can call this multiple times.
121143
*
144+
* @see #addFluidStack(Fluid, long) to add a Fluid with the default amount.
122145
* @see #addFluidStack(Fluid, long) to add a Fluid without a {@link DataComponentPatch}.
123146
* @since 19.8.3
124147
*/

CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import mezz.jei.api.recipe.RecipeIngredientRole;
1717
import net.minecraft.resources.ResourceLocation;
1818
import net.minecraft.world.item.ItemStack;
19+
import net.minecraft.world.level.ItemLike;
1920

2021
/**
2122
* Helps with the implementation of GUIs.
@@ -71,6 +72,17 @@ default IDrawable createDrawableItemStack(ItemStack ingredient) {
7172
return createDrawableIngredient(VanillaTypes.ITEM_STACK, ingredient);
7273
}
7374

75+
/**
76+
* Returns a 16x16 drawable for the given ItemLike,
77+
* matching the one JEI draws in the ingredient list.
78+
*
79+
* @see #createDrawableIngredient(IIngredientType, Object) for other ingredient types.
80+
* @since 19.18.1
81+
*/
82+
default IDrawable createDrawableItemLike(ItemLike itemLike) {
83+
return createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(itemLike));
84+
}
85+
7486
/**
7587
* Returns a 16x16 drawable for the given ingredient,
7688
* matching the one JEI draws in the ingredient list.

Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/IngredientAcceptorVoid.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mezz.jei.library.gui.recipes.layout.builder;
22

33
import mezz.jei.api.gui.builder.IIngredientAcceptor;
4+
import mezz.jei.api.gui.builder.IIngredientConsumer;
45
import mezz.jei.api.ingredients.IIngredientType;
56
import mezz.jei.api.ingredients.ITypedIngredient;
67
import net.minecraft.core.component.DataComponentPatch;
@@ -40,6 +41,11 @@ public IngredientAcceptorVoid addOptionalTypedIngredients(List<Optional<ITypedIn
4041
return this;
4142
}
4243

44+
@Override
45+
public IngredientAcceptorVoid addFluidStack(Fluid fluid) {
46+
return this;
47+
}
48+
4349
@Override
4450
public IngredientAcceptorVoid addFluidStack(Fluid fluid, long amount) {
4551
return this;

Library/src/main/java/mezz/jei/library/gui/recipes/layout/builder/RecipeSlotBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.base.Preconditions;
44
import it.unimi.dsi.fastutil.ints.IntSet;
5+
import mezz.jei.api.gui.builder.IIngredientConsumer;
56
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
67
import mezz.jei.api.gui.drawable.IDrawable;
78
import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable;
@@ -62,6 +63,12 @@ public <I> IRecipeSlotBuilder addIngredient(IIngredientType<I> ingredientType, I
6263
return this;
6364
}
6465

66+
@Override
67+
public IRecipeSlotBuilder addFluidStack(Fluid fluid) {
68+
this.ingredients.addFluidStack(fluid);
69+
return this;
70+
}
71+
6572
@Override
6673
public IRecipeSlotBuilder addFluidStack(Fluid fluid, long amount) {
6774
this.ingredients.addFluidStack(fluid, amount);

Library/src/main/java/mezz/jei/library/gui/recipes/supplier/builder/IngredientSlotBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mezz.jei.library.gui.recipes.supplier.builder;
22

3+
import mezz.jei.api.gui.builder.IIngredientConsumer;
34
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
45
import mezz.jei.api.gui.drawable.IDrawable;
56
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
@@ -39,6 +40,12 @@ public <I> IRecipeSlotBuilder addIngredient(IIngredientType<I> ingredientType, I
3940
return this;
4041
}
4142

43+
@Override
44+
public IRecipeSlotBuilder addFluidStack(Fluid fluid) {
45+
this.ingredients.addFluidStack(fluid);
46+
return this;
47+
}
48+
4249
@Override
4350
public IRecipeSlotBuilder addFluidStack(Fluid fluid, long amount) {
4451
this.ingredients.addFluidStack(fluid, amount);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
55
import it.unimi.dsi.fastutil.ints.IntSet;
66
import mezz.jei.api.gui.builder.IIngredientAcceptor;
7+
import mezz.jei.api.gui.builder.IIngredientConsumer;
78
import mezz.jei.api.ingredients.IIngredientHelper;
89
import mezz.jei.api.ingredients.IIngredientType;
910
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
@@ -87,6 +88,13 @@ public <I> DisplayIngredientAcceptor addTypedIngredient(ITypedIngredient<I> type
8788
return this;
8889
}
8990

91+
@SuppressWarnings("deprecation")
92+
@Override
93+
public DisplayIngredientAcceptor addFluidStack(Fluid fluid) {
94+
IPlatformFluidHelperInternal<?> fluidHelper = Services.PLATFORM.getFluidHelper();
95+
return addFluidInternal(fluidHelper, fluid.builtInRegistryHolder(), fluidHelper.bucketVolume(), DataComponentPatch.EMPTY);
96+
}
97+
9098
@SuppressWarnings("deprecation")
9199
@Override
92100
public DisplayIngredientAcceptor addFluidStack(Fluid fluid, long amount) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.base.Preconditions;
44
import mezz.jei.api.gui.builder.IIngredientAcceptor;
5+
import mezz.jei.api.gui.builder.IIngredientConsumer;
56
import mezz.jei.api.ingredients.IIngredientType;
67
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
78
import mezz.jei.api.ingredients.ITypedIngredient;
@@ -84,6 +85,13 @@ public <I> SimpleIngredientAcceptor addTypedIngredient(ITypedIngredient<I> typed
8485
return this;
8586
}
8687

88+
@SuppressWarnings("deprecation")
89+
@Override
90+
public SimpleIngredientAcceptor addFluidStack(Fluid fluid) {
91+
IPlatformFluidHelperInternal<?> fluidHelper = Services.PLATFORM.getFluidHelper();
92+
return addFluidInternal(fluidHelper, fluid.builtInRegistryHolder(), fluidHelper.bucketVolume(), DataComponentPatch.EMPTY);
93+
}
94+
8795
@SuppressWarnings("deprecation")
8896
@Override
8997
public SimpleIngredientAcceptor addFluidStack(Fluid fluid, long amount) {

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.0
77+
specificationVersion=19.18.1

0 commit comments

Comments
 (0)