From 44851cd8e96dc98de519a749003157ffc478130f Mon Sep 17 00:00:00 2001 From: Olav Bakke Svendsen Date: Sun, 22 Oct 2023 00:27:56 +0200 Subject: [PATCH] Fixes and improved configuration --- stockpile-switch.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/stockpile-switch.lua b/stockpile-switch.lua index e9393d2..84ec17b 100644 --- a/stockpile-switch.lua +++ b/stockpile-switch.lua @@ -1,17 +1,18 @@ -- stockpile-switch.lua -- forandre disse verdiene etter ønske! -local move_to_high = 500 -local move_to_low = 10000 +local signal_between = { 500, 10000 } +local invert_signal = false local update_frequency_seconds = 10 --------------------------------------- local inventory_address -for _,p in pairs(peripherals.getNames()) do +for _,p in pairs(peripheral.getNames()) do inventory_address = string.match(p, "^.*barrel.*$") end +local inventory = peripheral.wrap(inventory_address) local get_amount = function(item) local amount = 0 @@ -25,18 +26,24 @@ end local set_redstone = function(b) for _,side in pairs({"top", "bottom", "left", "right", "front", "back"}) do - rs.setOutput(side, b) + if invert_signal then + rs.setOutput(side, not b) + else + rs.setOutput(side, b) + end end return b end local redstone_state = false +local min = math.min(signal_between[1], signal_between[2]) +local max = math.max(signal_between[1], signal_between[2]) while true do - os.sleep(10) + os.sleep(update_frequency_seconds) local cobble_amount = get_amount("minecraft:cobblestone") - if cobble_amount >= move_to_high and not redstone_state then + if cobble_amount <= min and not redstone_state then redstone_state = set_redstone(true) - elseif cobble_amount <= move_to_low and redstone_state then + elseif cobble_amount >= max and redstone_state then redstone_state = set_redstone(false) end end -- 2.30.2