From ea3258ed7e841074c29749e48712aae315a22169 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Mon, 26 Feb 2018 05:12:17 -0500 Subject: [PATCH] crafter bug fixes --- apis/turtle/craft.lua | 6 +++--- apps/Crafter.lua | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apis/turtle/craft.lua b/apis/turtle/craft.lua index 645f91b..e7de07d 100644 --- a/apis/turtle/craft.lua +++ b/apis/turtle/craft.lua @@ -243,7 +243,7 @@ function Craft.getResourceList4(inRecipe, items, count) end -- given a certain quantity, return how many of those can be crafted -function Craft.getCraftableAmount(recipe, count, items, missing) +function Craft.getCraftableAmount(inRecipe, count, items, missing) local function sumItems(recipe, summedItems, count) local canCraft = 0 @@ -256,7 +256,7 @@ function Craft.getCraftableAmount(recipe, count, items, missing) summedItem = summedItem + sumItems(irecipe, summedItems, 1) end if summedItem <= 0 then - if missing then + if missing and not irecipe then missing.name = item end return canCraft @@ -271,7 +271,7 @@ function Craft.getCraftableAmount(recipe, count, items, missing) return canCraft end - return sumItems(recipe, { }, math.ceil(count / recipe.count)) + return sumItems(inRecipe, { }, math.ceil(count / inRecipe.count)) end function Craft.canCraft(item, count, items) diff --git a/apps/Crafter.lua b/apps/Crafter.lua index d47be23..0589d0e 100644 --- a/apps/Crafter.lua +++ b/apps/Crafter.lua @@ -72,14 +72,12 @@ local machines = { } local jobListGrid local listing, docked = false, false -local function getItem(items, inItem, ignoreDamage) +local function getItem(items, inItem, ignoreDamage, ignoreNbtHash) for _,item in pairs(items) do - if item.name == inItem.name then - if ignoreDamage then - return item - elseif item.damage == inItem.damage and item.nbtHash == inItem.nbtHash then - return item - end + if item.name == inItem.name and + (ignoreDamage or item.damage == inItem.damage) and + (ignoreNbtHash or item.nbtHash == inItem.nbtHash) then + return item end end end