fix crafting bug - missing ingredients
This commit is contained in:
@@ -476,7 +476,7 @@ local function findDroppedSaplings()
|
|||||||
local sensed = Util.reduce(raw, function(acc, b)
|
local sensed = Util.reduce(raw, function(acc, b)
|
||||||
Point.rotate(b, state.home.heading)
|
Point.rotate(b, state.home.heading)
|
||||||
b.x = Util.round(b.x) + turtle.point.x
|
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
|
b.z = Util.round(b.z) + turtle.point.z
|
||||||
if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
|
if b.y == 0 and string.find(b.displayName, 'sapling', 1, true) then
|
||||||
b.sapling = true
|
b.sapling = true
|
||||||
|
|||||||
@@ -191,14 +191,6 @@ local function adjustCounts(recipe, count, ingredients, storage)
|
|||||||
-- decrement ingredients used
|
-- decrement ingredients used
|
||||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
ingredients[key].count = ingredients[key].count - (icount * count)
|
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
|
end
|
||||||
|
|
||||||
-- increment crafted
|
-- 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 = math.floor((recipe.maxCount or 64) / recipe.count)
|
||||||
local maxCount = recipe.maxCount or math.floor(64 / recipe.count)
|
local maxCount = recipe.maxCount or math.floor(64 / recipe.count)
|
||||||
|
|
||||||
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
repeat
|
||||||
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
local craftedIngredient
|
||||||
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
|
|
||||||
|
|
||||||
local iqty = need - itemCount
|
for key,icount in pairs(Craft.sumIngredients(recipe)) do
|
||||||
local crafted = Craft.craftRecipeInternal(irecipe, iqty, storage, origItem)
|
local itemCount = Craft.getItemCount(origItem.ingredients, key)
|
||||||
if not origItem.forceCrafting and crafted < iqty then
|
local need = icount * count
|
||||||
return 0
|
if recipe.craftingTools and recipe.craftingTools[key] then
|
||||||
|
need = 1
|
||||||
end
|
end
|
||||||
if origItem.forceCrafting and crafted < iqty then
|
maxCount = math.min(maxCount, itemDB:getMaxCount(key))
|
||||||
canCraft = math.floor((itemCount + crafted) / icount)
|
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
|
end
|
||||||
end
|
until not craftedIngredient
|
||||||
_G._p = origItem.ingredients
|
|
||||||
local crafted = 0
|
local crafted = 0
|
||||||
while canCraft > 0 do
|
while canCraft > 0 do
|
||||||
local batch = math.min(canCraft, maxCount)
|
local batch = math.min(canCraft, maxCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user