Compare commits
4 commits
main
...
stock-mana
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23c8afe8ee | ||
|
|
ed4f44fc9d | ||
|
|
038b1b739c | ||
|
|
19cdb67281 |
1 changed files with 44 additions and 0 deletions
44
stock-manager.lua
Normal file
44
stock-manager.lua
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue