Skip to content

Commit bbfa92e

Browse files
committed
fix SpongeShapelessRecipe.matches
1 parent ed272c8 commit bbfa92e

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/main/java/org/spongepowered/common/item/recipe/crafting/shapeless/SpongeShapelessRecipe.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public boolean matches(final CraftingInput $$0, final Level $$1) {
7272
if (this.onlyVanillaIngredients) {
7373
return super.matches($$0, $$1);
7474
}
75-
return SpongeShapelessRecipe.matches($$0.items(), ((ShapelessRecipeAccessor) this).accessor$ingredients());
75+
return SpongeShapelessRecipe.matches($$0, ((ShapelessRecipeAccessor) this).accessor$ingredients());
7676
}
7777

7878
@Override
@@ -92,31 +92,36 @@ public ItemStack assemble(final CraftingInput $$0, final HolderLookup.Provider $
9292
return super.assemble($$0, $$1);
9393
}
9494

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

102+
// This can contain empty stacks
103+
// Probably would be better to store non-empty stack list on CraftingInput
104+
final List<ItemStack> stacks = input.items();
102105
// find matched stack -> ingredient list
103106
final Map<Integer, List<Integer>> matchesMap = new HashMap<>();
104-
for (int i = 0; i < ingredients.size(); i++) {
105-
Ingredient ingredient = ingredients.get(i);
107+
for (int i = 0; i < elements; i++) {
108+
final Ingredient ingredient = ingredients.get(i);
106109
boolean noMatch = true;
107110
for (int j = 0; j < stacks.size(); j++) {
108-
if (ingredient.test(stacks.get(j))) {
109-
matchesMap.computeIfAbsent(j, k -> new ArrayList<>()).add(i);;
111+
final ItemStack stack = stacks.get(j);
112+
if (!stack.isEmpty() && ingredient.test(stack)) {
113+
matchesMap.computeIfAbsent(j, k -> new ArrayList<>()).add(i);
110114
noMatch = false;
111115
}
112116
}
113117
if (noMatch) {
114-
// one ingredient had no match recipe does not match at all
118+
// One ingredient had no matching stack
115119
return false;
116120
}
117121
}
118122

119-
if (matchesMap.isEmpty()) {
123+
if (matchesMap.size() != elements) {
124+
// At least one stack had no matching ingredient
120125
return false;
121126
}
122127

0 commit comments

Comments
 (0)