diff --git a/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java b/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java index b5dd7ce1..efe7b053 100644 --- a/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java +++ b/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java @@ -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 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 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. *