diff --git a/stock-manager.lua b/stock-manager.lua new file mode 100644 index 0000000..43ef4c8 --- /dev/null +++ b/stock-manager.lua @@ -0,0 +1,44 @@ +-- Program that manages a stock system +-- For now this just means removing "waste" but in the future it could involve +-- - Displaying information to the user + +local STOCK_SOURCE = "" +local DISCARD_ADDR = "" +local LARGE_COMPACTING_ADDR = "" +local SMALL_COMPACTING_ADDR = "" + +local KEEP_ONLY = {} +KEEP_ONLY["minecraft:quartz"] = {6 * 64, DISCARD_ADDR} +KEEP_ONLY["minecraft:prismarine_shard"] = {2 * 64, DISCARD_ADDR} + +local DISCARD_REST = false + +local SLEEP_T = 10 + +function remove_waste(source, discard_rest) + local amounts_to_keep = KEEP_ONLY + local discard = function (item, amt, dest) + peripheral.call(source, "requestFiltered", dest, + { + name = item.name, + _requestCount = amt, + } + ) + end + for slot, item in pairs(peripheral.call(source, "stock")) do + if amounts_to_keep[item.name] ~= nil then + local excess = item.count - amounts_to_keep[item.name][1] + if excess > 0 then + discard(item, excess, amounts_to_keep[item.name][2]) + end + elseif DISCARD_REST then + discard(item, amt, DISCARD_ADDR) + end + os.sleep(1) + end +end + +while true do + remove_waste(STOCK_SOURCE, DISCARD_REST) + os.sleep(SLEEP_T) +end