storage_manager.lua: first pass at a storage manager to remove waste
This commit is contained in:
parent
4e0905b5f8
commit
a308d1d771
1 changed files with 39 additions and 0 deletions
39
storage_manager.lua
Normal file
39
storage_manager.lua
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
-- Program that manages a storage system
|
||||
-- For now this just means removing "waste" but in the future it could involve
|
||||
-- - Displaying information to the user
|
||||
-- - Freeing up slots where it can
|
||||
|
||||
local SOURCES =
|
||||
{
|
||||
}
|
||||
|
||||
local KEEP_ONLY = {}
|
||||
KEEP_ONLY["minecraft:quartz"] = 6 * 64
|
||||
KEEP_ONLY["minecraft:prismarine_shard"] = 2 * 64
|
||||
|
||||
function remove_excess_from (waste_inv, amounts_to_keep, source)
|
||||
for slot, item in pairs(peripheral.call(source, "list")) do
|
||||
if amounts_to_keep[item.name] ~= nil then
|
||||
local excess = item.count - amounts_to_keep[item.name]
|
||||
if excess > 0 then
|
||||
amounts_to_keep[item.name] = 0
|
||||
local result = peripheral.call(
|
||||
waste_inv, "pullItems", source, slot, excess
|
||||
)
|
||||
else
|
||||
amounts_to_keep[item.name] = -excess
|
||||
end
|
||||
end
|
||||
end
|
||||
return amounts_to_keep
|
||||
end
|
||||
|
||||
function remove_waste(sources, waste_inventory, amounts_to_keep)
|
||||
for _, src in ipairs(sources) do
|
||||
amounts_to_keep = remove_excess_from(waste_inventory, amounts_to_keep, src)
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
remove_waste(SOURCES, WASTE_INV, KEEP_ONLY)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue