From: Olav Bakke Svendsen Date: Sat, 21 Oct 2023 21:18:18 +0000 (+0200) Subject: Adding ad-hoc stockpile switch utility X-Git-Tag: skystone~30 X-Git-Url: http://git.olavbs.no/?a=commitdiff_plain;h=77d1cd082e73e13313ede59efa9d6cdb48f20ca4;p=cc.git Adding ad-hoc stockpile switch utility --- diff --git a/stockpile-switch.lua b/stockpile-switch.lua new file mode 100644 index 0000000..e9393d2 --- /dev/null +++ b/stockpile-switch.lua @@ -0,0 +1,42 @@ +-- stockpile-switch.lua + +-- forandre disse verdiene etter ønske! +local move_to_high = 500 +local move_to_low = 10000 +local update_frequency_seconds = 10 +--------------------------------------- + + + +local inventory_address +for _,p in pairs(peripherals.getNames()) do + inventory_address = string.match(p, "^.*barrel.*$") +end + +local get_amount = function(item) + local amount = 0 + for _,v in pairs(inventory.list()) do + if v and v.name == item then + amount = amount + v.count + end + end + return amount +end + +local set_redstone = function(b) + for _,side in pairs({"top", "bottom", "left", "right", "front", "back"}) do + rs.setOutput(side, b) + end + return b +end + +local redstone_state = false +while true do + os.sleep(10) + local cobble_amount = get_amount("minecraft:cobblestone") + if cobble_amount >= move_to_high and not redstone_state then + redstone_state = set_redstone(true) + elseif cobble_amount <= move_to_low and redstone_state then + redstone_state = set_redstone(false) + end +end