From cc162f22ac33173d917260c7b7543e8e5546cc62 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 29 Jan 2019 10:29:58 +0200 Subject: [PATCH] Fixed recipes not working when there are multiples of the same stack --- .../unicopia/enchanting/SpellRecipe.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellRecipe.java b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellRecipe.java index 238ec067..51c58a36 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellRecipe.java @@ -33,8 +33,6 @@ public class SpellRecipe extends Impl implements IRecipe { Item item = o.has("item") ? Item.getByNameOrId(o.get("item").getAsString()) : null; - - if (item != null) { int metadata = Math.max(0, o.has("data") ? o.get("data").getAsInt() : 0); int size = Math.max(1, o.has("count") ? o.get("count").getAsInt() : 1); @@ -78,11 +76,7 @@ public class SpellRecipe extends Impl implements IRecipe { ItemStack stack = inv.getStackInSlot(i); if (!stack.isEmpty()) { - if (toMatch.isEmpty() && !stack.isEmpty()) { - return false; - } - - if (!toMatch.isEmpty() && !toMatch.removeIf(s -> s.matches(stack, materialMult))) { + if (toMatch.isEmpty() || !removeMatch(toMatch, stack, materialMult)) { return false; } } @@ -90,6 +84,14 @@ public class SpellRecipe extends Impl implements IRecipe { return toMatch.isEmpty(); } + private boolean removeMatch(ArrayList toMatch, ItemStack stack, int materialMult) { + return toMatch.stream() + .filter(s -> s.matches(stack, materialMult)) + .findFirst() + .filter(toMatch::remove) + .isPresent(); + } + @Override public ItemStack getCraftingResult(InventoryCrafting inv) { return getRecipeOutput();