Advertisement
Xenogami

Reactor Control

Jan 13th, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. -- reactor_control.lua
  2.  
  3. -- 1. Wrap the reactor peripheral
  4. local SIDE = "back"  -- or whatever side/name your reactor is connected on
  5. local reactor = peripheral.wrap(SIDE)
  6.  
  7. if not reactor then
  8.   print("Error: No reactor found on side '" .. SIDE .. "'")
  9.   return
  10. end
  11.  
  12. -- 2. Main loop
  13. while true do
  14.   -- Retrieve energy data
  15.   local energyStored = reactor.getEnergyStored()        -- Current energy in the internal buffer
  16.   local maxEnergy = reactor.getEnergyCapacity() or 10000000 -- hypothetical max; adjust if the API differs
  17.   local energyPercent = (energyStored / maxEnergy) * 100
  18.  
  19.   -- Retrieve some optional data (depends on the mod’s API)
  20.   local isActive = reactor.getActive()
  21.   local fuelAmount = reactor.getFuelAmount()            -- total ingots or mB of fuel
  22.   local fuelTemp = reactor.getFuelTemperature()         -- in degrees (if available)
  23.   local casingTemp = reactor.getCasingTemperature()     -- in degrees (if available)
  24.  
  25.   -- Simple logic: if energy is almost full, turn reactor off; if low, turn it on
  26.   if energyPercent > 90 then
  27.     reactor.setActive(false)
  28.   elseif energyPercent < 30 then
  29.     reactor.setActive(true)
  30.   end
  31.  
  32.   -- Clear the screen and print data
  33.   term.clear()
  34.   term.setCursorPos(1,1)
  35.   print("=== Bigger Reactor Control ===")
  36.   print(string.format("Reactor status: %s", isActive and "ON" or "OFF"))
  37.   print(string.format("Energy: %.2f%%  (%d / %d)", energyPercent, energyStored, maxEnergy))
  38.   print(string.format("Fuel Amount: %d", fuelAmount or 0))
  39.  
  40.   if fuelTemp then
  41.     print(string.format("Fuel Temp: %.2f C", fuelTemp))
  42.   end
  43.   if casingTemp then
  44.     print(string.format("Casing Temp: %.2f C", casingTemp))
  45.   end
  46.  
  47.   -- Wait 5 seconds before checking again
  48.   sleep(5)
  49. end
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement