Skip to content

Commit 1231d58

Browse files
committed
Fix #3790 Air should not be displayed in recipes
1 parent da366e6 commit 1231d58

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public <T> DisplayIngredientAcceptor addIngredients(IIngredientType<T> ingredien
5858
ErrorUtil.checkNotNull(ingredientType, "ingredientType");
5959
Preconditions.checkNotNull(ingredients, "ingredients");
6060

61-
List<Optional<ITypedIngredient<T>>> typedIngredients = TypedIngredient.createUnvalidatedList(ingredientType, ingredients);
61+
List<Optional<ITypedIngredient<T>>> typedIngredients = TypedIngredient.createAndFilterInvalidList(ingredientManager, ingredientType, ingredients, false);
6262
@SuppressWarnings("unchecked")
6363
List<Optional<ITypedIngredient<?>>> castTypedIngredients = (List<Optional<ITypedIngredient<?>>>) (Object) typedIngredients;
6464
this.ingredients.addAll(castTypedIngredients);
@@ -70,7 +70,7 @@ public <T> DisplayIngredientAcceptor addIngredients(IIngredientType<T> ingredien
7070
public DisplayIngredientAcceptor addIngredients(Ingredient ingredient) {
7171
Preconditions.checkNotNull(ingredient, "ingredient");
7272

73-
List<Optional<ITypedIngredient<ItemStack>>> typedIngredients = TypedIngredient.createUnvalidatedList(ingredient);
73+
List<Optional<ITypedIngredient<ItemStack>>> typedIngredients = TypedIngredient.createAndFilterInvalidList(ingredientManager, ingredient, false);
7474
@SuppressWarnings("unchecked")
7575
List<Optional<ITypedIngredient<?>>> castTypedIngredients = (List<Optional<ITypedIngredient<?>>>) (Object) typedIngredients;
7676
this.ingredients.addAll(castTypedIngredients);
@@ -91,7 +91,9 @@ public <T> DisplayIngredientAcceptor addIngredient(IIngredientType<T> ingredient
9191
public <I> DisplayIngredientAcceptor addTypedIngredient(ITypedIngredient<I> typedIngredient) {
9292
ErrorUtil.checkNotNull(typedIngredient, "typedIngredient");
9393

94-
this.ingredients.add(Optional.of(typedIngredient));
94+
@SuppressWarnings("unchecked")
95+
Optional<ITypedIngredient<?>> copy = (Optional<ITypedIngredient<?>>) (Object) TypedIngredient.deepCopy(ingredientManager, typedIngredient);
96+
this.ingredients.add(copy);
9597

9698
return this;
9799
}
@@ -150,12 +152,10 @@ public DisplayIngredientAcceptor addOptionalTypedIngredients(List<Optional<IType
150152
}
151153

152154
private <T> void addIngredientInternal(IIngredientType<T> ingredientType, @Nullable T ingredient) {
153-
if (ingredient == null) {
154-
this.ingredients.add(Optional.empty());
155-
} else {
156-
ITypedIngredient<T> typedIngredient = TypedIngredient.createUnvalidated(ingredientType, ingredient);
157-
this.ingredients.add(Optional.of(typedIngredient));
158-
}
155+
Optional<ITypedIngredient<T>> result = TypedIngredient.createAndFilterInvalid(ingredientManager, ingredientType, ingredient, false);
156+
@SuppressWarnings("unchecked")
157+
Optional<ITypedIngredient<?>> castResult = (Optional<ITypedIngredient<?>>) (Object) result;
158+
this.ingredients.add(castResult);
159159
}
160160

161161
@UnmodifiableView

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,14 @@ public static <T> List<Optional<ITypedIngredient<T>>> createAndFilterInvalidList
101101
return results;
102102
}
103103

104-
public static <T> List<Optional<ITypedIngredient<T>>> createUnvalidatedList(
105-
IIngredientType<T> ingredientType,
106-
List<@Nullable T> ingredients
107-
) {
108-
List<Optional<ITypedIngredient<T>>> results = new ArrayList<>(ingredients.size());
109-
for (T ingredient : ingredients) {
110-
if (ingredient == null) {
111-
results.add(Optional.empty());
112-
} else {
113-
ITypedIngredient<T> result = createUnvalidated(ingredientType, ingredient);
114-
results.add(Optional.of(result));
115-
}
116-
}
117-
return results;
118-
}
119-
120-
public static List<Optional<ITypedIngredient<ItemStack>>> createUnvalidatedList(Ingredient ingredient) {
104+
public static List<Optional<ITypedIngredient<ItemStack>>> createAndFilterInvalidList(IIngredientManager ingredientManager, Ingredient ingredient, boolean normalize) {
121105
ItemStack[] itemStacks = ingredient.getItems();
106+
IIngredientHelper<ItemStack> ingredientHelper = ingredientManager.getIngredientHelper(VanillaTypes.ITEM_STACK);
122107

123108
List<Optional<ITypedIngredient<ItemStack>>> results = new ArrayList<>(itemStacks.length);
124109
for (ItemStack itemStack : itemStacks) {
125-
ITypedIngredient<ItemStack> result = TypedItemStack.create(itemStack);
126-
results.add(Optional.of(result));
110+
Optional<ITypedIngredient<ItemStack>> result = createAndFilterInvalid(ingredientHelper, VanillaTypes.ITEM_STACK, itemStack, normalize);
111+
results.add(result);
127112
}
128113
return results;
129114
}

0 commit comments

Comments
 (0)