diff --git a/.gitignore b/.gitignore index 13e8016ed..78843bd37 100644 --- a/.gitignore +++ b/.gitignore @@ -66,5 +66,5 @@ white-list.txt.converted whitelist.json world-20140811-075700.zip .cache - +.vscode/ gradle.properties diff --git a/src/mrtjp/projectred/expansion/TileProjectBench.scala b/src/mrtjp/projectred/expansion/TileProjectBench.scala index 8f89abb7c..10e34389f 100644 --- a/src/mrtjp/projectred/expansion/TileProjectBench.scala +++ b/src/mrtjp/projectred/expansion/TileProjectBench.scala @@ -244,18 +244,40 @@ class CraftingResultTestHelper for (i <- 0 until 9) { val prevInput = invCrafting.getStackInSlot(i) - if (!prevInput.isEmpty && !eatIngredient(0, { input => - invCrafting.setInventorySlotContents(i, input) - val resultSame = recipe.matches(invCrafting, w) && ItemStack.areItemStacksEqual(recipe.getCraftingResult(invCrafting), result) - invCrafting.setInventorySlotContents(i, prevInput) - resultSame - })) return (ItemStack.EMPTY, null) + if (!prevInput.isEmpty && !eatIngredient(0, getIngredientCount(i, _, result, w))) + return (ItemStack.EMPTY, null) } (result, recipe.getRemainingItems(invCrafting)) } - private def eatIngredient(startIdx:Int, matchFunc:ItemStack => Boolean):Boolean = + // Modded recipes may require more than one item in a crafting slot. Find the + // smallest candidate stack that still matches so normal recipes consume one. + private def getIngredientCount(slot:Int, input:ItemStack, result:ItemStack, w:World):Int = + { + val prevInput = invCrafting.getStackInSlot(slot) + val testInput = input.copy + var count = 1 + + try { + while (count <= input.getCount) { + testInput.setCount(count) + invCrafting.setInventorySlotContents(slot, testInput) + + if (recipe.matches(invCrafting, w) && + ItemStack.areItemStacksEqual(recipe.getCraftingResult(invCrafting), result)) + return count + + count += 1 + } + } finally { + invCrafting.setInventorySlotContents(slot, prevInput) + } + + 0 + } + + private def eatIngredient(startIdx:Int, getCount:ItemStack => Int):Boolean = { var i = startIdx def increment() = { @@ -263,9 +285,10 @@ class CraftingResultTestHelper } do { val stack2 = storage(i) - if (!stack2.isEmpty && matchFunc(stack2)) { - if (stack2.getCount >= 1) { - stack2.shrink(1) + if (!stack2.isEmpty) { + val count = getCount(stack2) + if (count > 0) { + stack2.shrink(count) return true } }