Skip to content

Commit

Permalink
Fix #3790 Air should not be displayed in recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Oct 3, 2024
1 parent da366e6 commit 1231d58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public <T> DisplayIngredientAcceptor addIngredients(IIngredientType<T> ingredien
ErrorUtil.checkNotNull(ingredientType, "ingredientType");
Preconditions.checkNotNull(ingredients, "ingredients");

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

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

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

return this;
}
Expand Down Expand Up @@ -150,12 +152,10 @@ public DisplayIngredientAcceptor addOptionalTypedIngredients(List<Optional<IType
}

private <T> void addIngredientInternal(IIngredientType<T> ingredientType, @Nullable T ingredient) {
if (ingredient == null) {
this.ingredients.add(Optional.empty());
} else {
ITypedIngredient<T> typedIngredient = TypedIngredient.createUnvalidated(ingredientType, ingredient);
this.ingredients.add(Optional.of(typedIngredient));
}
Optional<ITypedIngredient<T>> result = TypedIngredient.createAndFilterInvalid(ingredientManager, ingredientType, ingredient, false);
@SuppressWarnings("unchecked")
Optional<ITypedIngredient<?>> castResult = (Optional<ITypedIngredient<?>>) (Object) result;
this.ingredients.add(castResult);
}

@UnmodifiableView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,14 @@ public static <T> List<Optional<ITypedIngredient<T>>> createAndFilterInvalidList
return results;
}

public static <T> List<Optional<ITypedIngredient<T>>> createUnvalidatedList(
IIngredientType<T> ingredientType,
List<@Nullable T> ingredients
) {
List<Optional<ITypedIngredient<T>>> results = new ArrayList<>(ingredients.size());
for (T ingredient : ingredients) {
if (ingredient == null) {
results.add(Optional.empty());
} else {
ITypedIngredient<T> result = createUnvalidated(ingredientType, ingredient);
results.add(Optional.of(result));
}
}
return results;
}

public static List<Optional<ITypedIngredient<ItemStack>>> createUnvalidatedList(Ingredient ingredient) {
public static List<Optional<ITypedIngredient<ItemStack>>> createAndFilterInvalidList(IIngredientManager ingredientManager, Ingredient ingredient, boolean normalize) {
ItemStack[] itemStacks = ingredient.getItems();
IIngredientHelper<ItemStack> ingredientHelper = ingredientManager.getIngredientHelper(VanillaTypes.ITEM_STACK);

List<Optional<ITypedIngredient<ItemStack>>> results = new ArrayList<>(itemStacks.length);
for (ItemStack itemStack : itemStacks) {
ITypedIngredient<ItemStack> result = TypedItemStack.create(itemStack);
results.add(Optional.of(result));
Optional<ITypedIngredient<ItemStack>> result = createAndFilterInvalid(ingredientHelper, VanillaTypes.ITEM_STACK, itemStack, normalize);
results.add(result);
}
return results;
}
Expand Down

0 comments on commit 1231d58

Please sign in to comment.