Skip to content

Commit

Permalink
Add a way to find all matches at once for recipematches
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Jun 5, 2016
1 parent 3ff8b2d commit 7925eb0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ public RecipeMatch.Match matches(ItemStack[] stacks, int minAmount) {
return new RecipeMatch.Match(foundStacks, sum);
}

public RecipeMatch.Match matchesRecursively(ItemStack[] stacks) {
stacks = copyItemStackArray(stacks); // copy so we don't modify original

List<RecipeMatch.Match> matches = Lists.newLinkedList();

RecipeMatch.Match match;
int sum = 0;
while((match = matches(stacks)) != null) {
matches.add(match);
RecipeMatch.removeMatch(stacks, match);

sum += match.amount;
}

// merge all found matches into one match
List<ItemStack> foundStacks = Lists.newLinkedList();
for(RecipeMatch.Match m : matches) {
foundStacks.addAll(m.stacks);
}

return new RecipeMatch.Match(foundStacks, sum);
}

/**
* Associates an oredict entry with this material. Used for repairing and other.
*
Expand Down

0 comments on commit 7925eb0

Please sign in to comment.