util refactor + milo bulk crafting

This commit is contained in:
kepler155c@gmail.com
2019-02-26 09:47:44 -05:00
parent 4303aeb1f8
commit 442f1c4d47
7 changed files with 51 additions and 25 deletions

View File

@@ -96,28 +96,32 @@ local function machineCraft(recipe, storage, machineName, request, count, item)
end
end
local xferred = { }
for k,v in pairs(recipe.ingredients) do
local provided = storage:export(machine, k, count, splitKey(v))
xferred[k] = {
key = v,
count = provided,
}
if provided ~= count then
-- take back out whatever we put in
for k2,v2 in pairs(xferred) do
if v2.count > 0 then
storage:import(machine, k2, v2.count, splitKey(v2.key))
local pending = item.pending[recipe.result] or 0
if count > 0 then
local xferred = { }
for k,v in pairs(recipe.ingredients) do
local provided = storage:export(machine, k, count, splitKey(v))
xferred[k] = {
key = v,
count = provided,
}
if provided ~= count then
-- take back out whatever we put in
for k2,v2 in pairs(xferred) do
if v2.count > 0 then
storage:import(machine, k2, v2.count, splitKey(v2.key))
end
end
request.status = 'Invalid recipe'
request.statusCode = Craft.STATUS_ERROR
return
end
request.status = 'Invalid recipe'
request.statusCode = Craft.STATUS_ERROR
return
end
end
request.status = 'processing'
request.statusCode = Craft.STATUS_INFO
item.pending[recipe.result] = count * recipe.count
item.pending[recipe.result] = pending + (count * recipe.count)
end
local function turtleCraft(recipe, storage, request, count)
@@ -202,12 +206,14 @@ end
function Craft.craftRecipeInternal(recipe, count, storage, origItem)
local request = origItem.ingredients[recipe.result]
--[[
if origItem.pending[recipe.result] then
request.status = 'processing'
request.statusCode = Craft.STATUS_INFO
return 0
end
--]]
count = count - (origItem.pending[recipe.result] or 0)
local canCraft = Craft.getCraftableAmount(recipe, count, origItem.ingredients)
if not origItem.forceCrafting and canCraft == 0 then
return 0