Advertisement
Darknio

Reactor Bigger reactor

May 13th, 2025
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. -- Konfiguration
  2. local reactorName = "BiggerReactors_Reactor_0"
  3. local monitorName = "monitor_0"
  4. local maxEnergy = 10000000  -- Maximaler Energiespeicher (für Prozentanzeige)
  5.  
  6. -- Initialisierung
  7. local monitor = peripheral.wrap(monitorName)
  8. local reactor = peripheral.wrap(reactorName)
  9.  
  10. if not reactor then
  11.     error("Reaktor nicht gefunden! Bitte Peripheral-Namen prüfen.")
  12. end
  13.  
  14. -- Farben und Status
  15. local autostart = false
  16. local status = "Aus"
  17. local toggleReactor = true
  18.  
  19. -- Hilfsfunktionen
  20. local function clearScreen()
  21.     monitor.setBackgroundColor(colors.black)
  22.     monitor.clear()
  23.     monitor.setCursorPos(1, 1)
  24. end
  25.  
  26. local function getReactorData()
  27.     local energyStats = reactor.getEnergyStats()
  28.     local energy = energyStats.energyStored
  29.  
  30.     local fuel = reactor.getFuelAmount().amount
  31.     local fuelHeat = reactor.getFuelTemperature()
  32.     local casingHeat = reactor.getCasingTemperature()
  33.     local rfPerTick = reactor.getEnergyProducedLastTick()
  34.     local active = reactor.getActive()
  35.  
  36.     return {
  37.         energy = energy,
  38.         fuel = fuel,
  39.         fuelHeat = fuelHeat,
  40.         casingHeat = casingHeat,
  41.         rfPerTick = rfPerTick,
  42.         active = active
  43.     }
  44. end
  45.  
  46. local function displayHeader()
  47.     monitor.setBackgroundColor(colors.blue)
  48.     monitor.setTextColor(colors.white)
  49.     monitor.setCursorPos(1, 1)
  50.     monitor.write(" Bigger Reactor Monitor ")
  51.    
  52.     monitor.setCursorPos(25, 1)
  53.     monitor.write(textutils.formatTime(os.time(), true))
  54.    
  55.     monitor.setBackgroundColor(colors.black)
  56.     monitor.setTextColor(colors.white)
  57. end
  58.  
  59. local function displayStatus(data)
  60.     local percent = math.floor((data.energy / maxEnergy) * 100)
  61.  
  62.     monitor.setCursorPos(1, 2)
  63.     monitor.write("Autostart: ")
  64.     monitor.setTextColor(autostart and colors.lime or colors.red)
  65.     monitor.write(autostart and "An" or "Aus")
  66.  
  67.     monitor.setTextColor(colors.white)
  68.     monitor.setCursorPos(1, 3)
  69.     monitor.write("Status: ")
  70.     monitor.setTextColor(data.active and colors.lime or colors.red)
  71.     monitor.write(data.active and "An" or "Aus")
  72.  
  73.     monitor.setTextColor(colors.white)
  74.     monitor.setCursorPos(1, 4)
  75.     monitor.write("Brennstoff: " .. math.ceil(data.fuel))
  76.     monitor.setCursorPos(1, 5)
  77.     monitor.write("Fuel-Temp : " .. math.ceil(data.fuelHeat))
  78.     monitor.setCursorPos(1, 6)
  79.     monitor.write("CasingTemp: " .. math.ceil(data.casingHeat))
  80.     monitor.setCursorPos(1, 7)
  81.     monitor.write("RF/t      : " .. math.ceil(data.rfPerTick))
  82.     monitor.setCursorPos(1, 8)
  83.     monitor.write("Energie   : " .. percent .. "%")
  84. end
  85.  
  86. local function handleAutostart(data)
  87.     if not autostart then return end
  88.     if data.energy < (maxEnergy * 0.4) then
  89.         reactor.setActive(true)
  90.     elseif data.energy > (maxEnergy * 0.9) then
  91.         reactor.setActive(false)
  92.     end
  93. end
  94.  
  95. local function runMonitor()
  96.     while true do
  97.         clearScreen()
  98.         local data = getReactorData()
  99.         displayHeader()
  100.         displayStatus(data)
  101.         handleAutostart(data)
  102.         sleep(0.5)
  103.     end
  104. end
  105.  
  106. local function handleTouch()
  107.     while true do
  108.         local event, side, x, y = os.pullEvent("monitor_touch")
  109.         if y == 2 then
  110.             autostart = not autostart
  111.         elseif y == 3 then
  112.             local currentState = reactor.getActive()
  113.             reactor.setActive(not currentState)
  114.         end
  115.     end
  116. end
  117.  
  118. -- Start
  119. parallel.waitForAny(runMonitor, handleTouch)
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement