feat: create stock manager for removing excess stock
This commit is contained in:
parent
9a8f81e428
commit
19cdb67281
1 changed files with 47 additions and 0 deletions
47
stock-manager.lua
Normal file
47
stock-manager.lua
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue