diff --git a/storage_manager.lua b/storage_manager.lua new file mode 100644 index 0000000..b321cd5 --- /dev/null +++ b/storage_manager.lua @@ -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