From 6ac98161893db3a719034bc89748ad51af8afbda Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 6 Jan 2019 04:15:36 -0500 Subject: [PATCH] fix crafting bug - missing ingredients --- farms/superTreefarm.lua | 2 +- milo/apis/craft2.lua | 55 ++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/farms/superTreefarm.lua b/farms/superTreefarm.lua index 3611286..c2a8da7 100644 --- a/farms/superTreefarm.lua +++ b/farms/superTreefarm.lua @@ -476,7 +476,7 @@ local function findDroppedSaplings() local sensed = Util.reduce(raw, function(acc, b) Point.rotate(b, state.home.heading) b.x = Util.round(b.x) + turtle.point.x - b.y = Util.round(b.y) + turtle.point.y + b.y = math.floor(b.y) + turtle.point.y b.z = Util.round(b.z) + turtle.point.z if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then b.sapling = true diff --git a/milo/apis/craft2.lua b/milo/apis/craft2.lua index 32c4981..68173d2 100644 --- a/milo/apis/craft2.lua +++ b/milo/apis/craft2.lua @@ -191,14 +191,6 @@ local function adjustCounts(recipe, count, ingredients, storage) -- decrement ingredients used for key,icount in pairs(Craft.sumIngredients(recipe)) do ingredients[key].count = ingredients[key].count - (icount * count) - if ingredients[key].count == 0 and not storage.cache[key] then - -- - elseif not storage.cache[key] then - _debug({ key, ingredients[key].count, 'nocache' }) - elseif storage.cache[key].count ~= ingredients[key].count then - _debug({ key, ingredients[key].count, storage.cache[key].count }) - - end end -- increment crafted @@ -232,30 +224,37 @@ function Craft.craftRecipeInternal(recipe, count, storage, origItem) --local maxCount = math.floor((recipe.maxCount or 64) / recipe.count) local maxCount = recipe.maxCount or math.floor(64 / recipe.count) - for key,icount in pairs(Craft.sumIngredients(recipe)) do - local itemCount = Craft.getItemCount(origItem.ingredients, key) - local need = icount * count - if recipe.craftingTools and recipe.craftingTools[key] then - need = 1 - end - maxCount = math.min(maxCount, itemDB:getMaxCount(key)) - if itemCount < need then - local irecipe = Craft.findRecipe(key) - if not irecipe then - return 0 - end + repeat + local craftedIngredient - local iqty = need - itemCount - local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem) - if not origItem.forceCrafting and crafted < iqty then - return 0 + for key,icount in pairs(Craft.sumIngredients(recipe)) do + local itemCount = Craft.getItemCount(origItem.ingredients, key) + local need = icount * count + if recipe.craftingTools and recipe.craftingTools[key] then + need = 1 end - if origItem.forceCrafting and crafted < iqty then - canCraft = math.floor((itemCount + crafted) / icount) + maxCount = math.min(maxCount, itemDB:getMaxCount(key)) + if itemCount < need then + local irecipe = Craft.findRecipe(key) + if not irecipe then + return 0 + end + + local iqty = need - itemCount + local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem) + if not origItem.forceCrafting and crafted < iqty then + return 0 + end + if origItem.forceCrafting and crafted < iqty then + canCraft = math.floor((itemCount + crafted) / icount) + end + if crafted > 0 then + craftedIngredient = true + end end end - end -_G._p = origItem.ingredients + until not craftedIngredient + local crafted = 0 while canCraft > 0 do local batch = math.min(canCraft, maxCount)