SHARE
TWEET

Untitled

a guest Feb 21st, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Input Signals:
  2. -- control
  3. -- comparator
  4. -- Output Signals:
  5. -- reactor: control and (comparator < threshold)
  6.  
  7. local signal_comparator = "top"
  8. local signal_control = "right"
  9. local signal_reactor = "front"
  10. local signal_reactor_local = "left"
  11. local monitor = peripheral.wrap("back")
  12.  
  13. local threshold = 12
  14.  
  15. local current_reactor_signal = false
  16. local last_read_comparator_level = 0
  17.  
  18. local function update()
  19.     local comparator = redstone.getAnalogInput(signal_comparator)
  20.     local control = redstone.getInput(signal_control)
  21.  
  22.     local reactor = control and (comparator < 12)
  23.  
  24.     redstone.setOutput(signal_reactor, reactor)
  25.     redstone.setOutput(signal_reactor_local, reactor)
  26.  
  27.     current_reactor_signal = reactor
  28.     last_read_comparator_level = comparator
  29. end
  30.  
  31. local function drawBox(x, y, width, height, color)
  32.     monitor.setBackgroundColor(color)
  33.     for i = x, x + width do
  34.         for j = y, y + height do
  35.             monitor.setCursorPos(i, j)
  36.             monitor.write(" ")
  37.         end
  38.     end
  39.     monitor.setBackgroundColor(colors.black)
  40. end
  41.  
  42. local function render()
  43.     local width, height = monitor.getSize()
  44.  
  45.     monitor.clear()
  46.  
  47.     monitor.setTextScale(2)
  48.     monitor.setCursorPos(1, 1)
  49.     monitor.write("Reactor Buffer State:")
  50.     monitor.setTextScale(1)
  51.  
  52.     local bar_x = 1
  53.     local bar_y = 5
  54.     local bar_width = width - 2
  55.     local inner_width = bar_width - 2
  56.     local bar_height = height - 6
  57.     local inner_height = bar_height - 2
  58.  
  59.  
  60.     drawBox(bar_x, bar_y, bar_width, bar_height, colors.yellow)
  61.     local fill_percent = last_read_comparator_level / 15
  62.     local fill_level = math.floor(inner_width * fill_percent)
  63.     drawBox(bar_x + 1, bar_y + 1, fill_level, inner_height, colors.red)
  64. end
  65.  
  66.  
  67. local function run()
  68.     update()
  69.     render()
  70.     while true do
  71.         if redstone.getAnalogInput(signal_comparator) ~= last_read_comparator_level then
  72.             update()
  73.             render()
  74.         end
  75.         os.sleep(2)
  76.     end
  77. end
  78.  
  79. run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top