mirror of
https://github.com/mt-mods/pipeworks.git
synced 2025-05-11 05:10:22 +02:00
use has_room_for_output
This commit is contained in:
parent
2638d41d48
commit
a8570f6071
@ -148,31 +148,19 @@ local function calculate_consumption(inv_index, consumption_with_groups)
|
||||
return consumption
|
||||
end
|
||||
|
||||
local function autocraft(inventory, craft)
|
||||
if not craft then return false end
|
||||
|
||||
-- check if output and all replacements fit in dst
|
||||
local output = craft.output.item
|
||||
local out_items = count_index(craft.decremented_input.items)
|
||||
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
|
||||
for _,item in pairs(inventory:get_list("dst")) do
|
||||
for _, item in pairs(list_output) do
|
||||
if item:is_empty() then
|
||||
empty_count = empty_count + 1
|
||||
else
|
||||
local name = item:get_name()
|
||||
if out_items[name] then
|
||||
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
|
||||
for _,count in pairs(out_items) do
|
||||
for _, count in pairs(index_output) do
|
||||
if count > 0 then
|
||||
empty_count = empty_count - 1
|
||||
@ -185,6 +173,17 @@ local function has_room_for_output(list_output, index_output)
|
||||
return true
|
||||
end
|
||||
|
||||
local function autocraft(inventory, craft)
|
||||
if not craft then return false end
|
||||
|
||||
-- check if output and all replacements fit in dst
|
||||
local output = craft.output.item
|
||||
local out_items = count_index(craft.decremented_input)
|
||||
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
|
||||
if not has_room_for_output(inventory:get_list("dst"), out_items) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- check if we have enough material available
|
||||
local inv_index = count_index(inventory:get_list("src"))
|
||||
local consumption = calculate_consumption(inv_index, craft.consumption)
|
||||
|
Loading…
x
Reference in New Issue
Block a user