From 19cdb6728188440f93736d4f1e882cf490719475 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Mon, 22 Dec 2025 21:50:23 -0500 Subject: [PATCH 1/4] feat: create stock manager for removing excess stock --- stock-manager.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 stock-manager.lua diff --git a/stock-manager.lua b/stock-manager.lua new file mode 100644 index 0000000..b04bb66 --- /dev/null +++ b/stock-manager.lua @@ -0,0 +1,47 @@ +-- 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 + amounts_to_keep[item.name][1] = 0 + discard(item, excess, amounts_to_keep[item.name][2]) + else + amounts_to_keep[item.name][1] = -excess + end + elseif DISCARD_REST then + discard(item, amt, DISCARD_ADDR) + end + os.sleep(1) + end +end + +while true do + remove_waste(STOCK_SOURCE, DISCARD_ADDR, DISCARD_REST) + os.sleep(SLEEP_T) +end From 038b1b739cbc8107b5eba74c9a96484db2685ac0 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 26 Dec 2025 22:04:05 -0500 Subject: [PATCH 2/4] fix: remove syntax error --- stock-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock-manager.lua b/stock-manager.lua index b04bb66..e912b81 100644 --- a/stock-manager.lua +++ b/stock-manager.lua @@ -42,6 +42,6 @@ function remove_waste(source, discard_rest) end while true do - remove_waste(STOCK_SOURCE, DISCARD_ADDR, DISCARD_REST) + remove_waste(STOCK_SOURCE, DISCARD_REST) os.sleep(SLEEP_T) end From ed4f44fc9d08510819c79ab0f7ec6e436c844edb Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 26 Dec 2025 23:04:33 -0500 Subject: [PATCH 3/4] fix: remove syntax error --- stock-manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stock-manager.lua b/stock-manager.lua index e912b81..520b9bc 100644 --- a/stock-manager.lua +++ b/stock-manager.lua @@ -18,7 +18,7 @@ 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 + peripheral.call(source, "requestFiltered", dest, { name = item.name, _requestCount = amt, From 23c8afe8ee8fe9f73cf10c4eecd2778b72d5fc05 Mon Sep 17 00:00:00 2001 From: Emerson Rosen-Jones Date: Fri, 26 Dec 2025 23:05:09 -0500 Subject: [PATCH 4/4] fix: keep config static --- stock-manager.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/stock-manager.lua b/stock-manager.lua index 520b9bc..43ef4c8 100644 --- a/stock-manager.lua +++ b/stock-manager.lua @@ -29,10 +29,7 @@ function remove_waste(source, discard_rest) if amounts_to_keep[item.name] ~= nil then local excess = item.count - amounts_to_keep[item.name][1] if excess > 0 then - amounts_to_keep[item.name][1] = 0 discard(item, excess, amounts_to_keep[item.name][2]) - else - amounts_to_keep[item.name][1] = -excess end elseif DISCARD_REST then discard(item, amt, DISCARD_ADDR)