MrElders

reactor_gui

Oct 24th, 2025
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. -- === Reactor Monitor & Control Script ===
  2. -- CC:Tweaked - Extreme Reactors (ATM10)
  3. -- Monitor GUI + Auto Control + Manual Button
  4. -- Ethan Edition
  5.  
  6. local REACTOR_NAME = "BigReactors-Reactor_0"  -- Adjust if different
  7. local MONITOR_NAME = "monitor_0"             -- Adjust if different
  8.  
  9. local autoControl = true
  10. local reactor = peripheral.wrap(REACTOR_NAME)
  11. local monitor = peripheral.wrap(MONITOR_NAME)
  12.  
  13. local function centerText(line, text)
  14.   local w, _ = monitor.getSize()
  15.   monitor.setCursorPos(math.floor((w - #text) / 2) + 1, line)
  16.   monitor.write(text)
  17. end
  18.  
  19. local function drawButton(label, active)
  20.   local w, h = monitor.getSize()
  21.   monitor.setCursorPos(2, h - 1)
  22.   if active then
  23.     monitor.setBackgroundColor(colors.red)
  24.     monitor.setTextColor(colors.white)
  25.   else
  26.     monitor.setBackgroundColor(colors.lime)
  27.     monitor.setTextColor(colors.black)
  28.   end
  29.   monitor.write(" [ " .. label .. " ] ")
  30.   monitor.setBackgroundColor(colors.black)
  31. end
  32.  
  33. local function drawGUI()
  34.   monitor.clear()
  35.   monitor.setTextColor(colors.cyan)
  36.  
  37.   centerText(1, "=== Reactor Control ===")
  38.  
  39.   monitor.setTextColor(colors.white)
  40.   monitor.setCursorPos(1, 3)
  41.   monitor.write("Status: ")
  42.   monitor.setTextColor(reactor.getActive() and colors.lime or colors.red)
  43.   monitor.write(reactor.getActive() and "ONLINE" or "OFFLINE")
  44.  
  45.   monitor.setTextColor(colors.white)
  46.   monitor.setCursorPos(1, 4)
  47.   monitor.write(string.format("RF/t:      %.0f", reactor.getEnergyProducedLastTick()))
  48.  
  49.   monitor.setCursorPos(1, 5)
  50.   monitor.write(string.format("Fuel:      %.2f%%", reactor.getFuelAmount() / reactor.getFuelAmountMax() * 100))
  51.  
  52.   monitor.setCursorPos(1, 6)
  53.   monitor.write(string.format("Temp:      %.1f C", reactor.getFuelTemperature()))
  54.  
  55.   monitor.setCursorPos(1, 7)
  56.   monitor.write(string.format("Energy:    %.0f / %.0f RF",
  57.     reactor.getEnergyStored(), reactor.getEnergyCapacity()))
  58.  
  59.   monitor.setCursorPos(1, 8)
  60.   monitor.write("Mode: " .. (autoControl and "AUTO" or "MANUAL"))
  61.  
  62.   drawButton(reactor.getActive() and "TURN OFF" or "TURN ON", not autoControl)
  63. end
  64.  
  65. local function toggleReactor()
  66.   reactor.setActive(not reactor.getActive())
  67. end
  68.  
  69. local function toggleControlMode()
  70.   autoControl = not autoControl
  71. end
  72.  
  73. local function handleTouch(x, y)
  74.   local _, h = monitor.getSize()
  75.   if y == h - 1 then
  76.     if autoControl then
  77.       toggleControlMode()
  78.     else
  79.       toggleReactor()
  80.     end
  81.   end
  82. end
  83.  
  84. local function autoControlLogic()
  85.   local stored = reactor.getEnergyStored()
  86.   local max = reactor.getEnergyCapacity()
  87.  
  88.   if stored / max >= 0.95 then
  89.     reactor.setActive(false)
  90.   elseif stored / max <= 0.20 then
  91.     reactor.setActive(true)
  92.   end
  93. end
  94.  
  95. -- === Startup ===
  96. monitor.setTextScale(1)
  97. monitor.setBackgroundColor(colors.black)
  98. monitor.clear()
  99. monitor.setCursorBlink(false)
  100.  
  101. -- === Event Loop ===
  102. while true do
  103.   drawGUI()
  104.  
  105.   if autoControl then
  106.     autoControlLogic()
  107.   end
  108.  
  109.   local event, side, x, y = os.pullEvent()
  110.  
  111.   if event == "monitor_touch" then
  112.     handleTouch(x, y)
  113.   end
  114. end
  115.  
Advertisement
Add Comment
Please, Sign In to add comment