Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public boolean matches(final CraftingInput $$0, final Level $$1) {
if (this.onlyVanillaIngredients) {
return super.matches($$0, $$1);
}
return SpongeShapelessRecipe.matches($$0.items(), this.getIngredients());
return SpongeShapelessRecipe.matches($$0, this.getIngredients());
}

@Override
Expand Down Expand Up @@ -158,19 +158,22 @@ public ItemStack getResultItem(final HolderLookup.Provider $$1) {
}

private static boolean
matches(List<ItemStack> stacks, List<Ingredient> ingredients) {
matches(CraftingInput input, List<Ingredient> ingredients) {
final int elements = ingredients.size();
if (stacks.size() < elements) {
if (input.ingredientCount() != elements) {
// The amount of non-empty stacks doesn't match the amount of ingredients
return false;
}

final List<ItemStack> stacks = input.items();
// find matched stack -> ingredient list
final Map<Integer, List<Integer>> matchesMap = new HashMap<>();
for (int i = 0; i < ingredients.size(); i++) {
Ingredient ingredient = ingredients.get(i);
boolean noMatch = true;
for (int j = 0; j < stacks.size(); j++) {
if (ingredient.test(stacks.get(j))) {
final ItemStack stack = stacks.get(j);
if (!stack.isEmpty() && ingredient.test(stack)) {
matchesMap.computeIfAbsent(j, k -> new ArrayList<>()).add(i);;
noMatch = false;
}
Expand All @@ -181,7 +184,8 @@ public ItemStack getResultItem(final HolderLookup.Provider $$1) {
}
}

if (matchesMap.isEmpty()) {
if (matchesMap.size() != elements) {
// At least one stack had no matching ingredient
return false;
}

Expand Down