Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ white-list.txt.converted
whitelist.json
world-20140811-075700.zip
.cache

.vscode/
gradle.properties
43 changes: 33 additions & 10 deletions src/mrtjp/projectred/expansion/TileProjectBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,51 @@ 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() = {
i = (i + 1) % storage.length; i
}
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
}
}
Expand Down