mirror of
https://github.com/mt-mods/pipeworks.git
synced 2025-05-10 20:50:22 +02:00
add function has_room_for_output
moving the output space calculation into its own function helps keep autocraft() short and overseeable
This commit is contained in:
parent
7c210a5841
commit
2638d41d48
@ -155,18 +155,25 @@ local function autocraft(inventory, craft)
|
|||||||
local output = craft.output.item
|
local output = craft.output.item
|
||||||
local out_items = count_index(craft.decremented_input.items)
|
local out_items = count_index(craft.decremented_input.items)
|
||||||
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
|
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
|
||||||
|
local function has_room_for_output(list_output, index_output)
|
||||||
|
local name
|
||||||
local empty_count = 0
|
local empty_count = 0
|
||||||
for _,item in pairs(inventory:get_list("dst")) do
|
for _,item in pairs(inventory:get_list("dst")) do
|
||||||
|
for _, item in pairs(list_output) do
|
||||||
if item:is_empty() then
|
if item:is_empty() then
|
||||||
empty_count = empty_count + 1
|
empty_count = empty_count + 1
|
||||||
else
|
else
|
||||||
local name = item:get_name()
|
local name = item:get_name()
|
||||||
if out_items[name] then
|
if out_items[name] then
|
||||||
out_items[name] = out_items[name] - item:get_free_space()
|
out_items[name] = out_items[name] - item:get_free_space()
|
||||||
|
name = item:get_name()
|
||||||
|
if index_output[name] then
|
||||||
|
index_output[name] = index_output[name] - item:get_free_space()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _,count in pairs(out_items) do
|
for _,count in pairs(out_items) do
|
||||||
|
for _, count in pairs(index_output) do
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
empty_count = empty_count - 1
|
empty_count = empty_count - 1
|
||||||
end
|
end
|
||||||
@ -175,6 +182,9 @@ local function autocraft(inventory, craft)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
-- check if we have enough material available
|
-- check if we have enough material available
|
||||||
local inv_index = count_index(inventory:get_list("src"))
|
local inv_index = count_index(inventory:get_list("src"))
|
||||||
local consumption = calculate_consumption(inv_index, craft.consumption)
|
local consumption = calculate_consumption(inv_index, craft.consumption)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user