Adding ad-hoc stockpile switch utility
authorOlav Bakke Svendsen <mail@olavbs.no>
Sat, 21 Oct 2023 21:18:18 +0000 (23:18 +0200)
committerOlav Bakke Svendsen <mail@olavbs.no>
Sat, 21 Oct 2023 21:18:18 +0000 (23:18 +0200)
stockpile-switch.lua [new file with mode: 0644]

diff --git a/stockpile-switch.lua b/stockpile-switch.lua
new file mode 100644 (file)
index 0000000..e9393d2
--- /dev/null
@@ -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