Advertisement
BigBlow_

Fission_redstone_autorun

Jul 8th, 2025 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- CONFIGURATION
  2. local leverSide = "front"           -- Side of the real lever (physical lever on the computer)
  3. local relayRedstoneSide = "right"   -- Side of redstone input on the relays
  4. local loopDelay = 1.0               -- Delay between each loop in seconds
  5.  
  6. -- VARIABLES
  7. local redstoneRelays = {}
  8. local reactor = nil
  9.  
  10. -- SCAN
  11. local function scanPeripherals()
  12.   redstoneRelays = {}
  13.   reactor = peripheral.find("fissionReactorLogicAdapter")
  14.   if reactor then
  15.     print("Reactor detected")
  16.   else
  17.     print("Error: reactor not found")
  18.   end
  19.   for _, name in ipairs(peripheral.getNames()) do
  20.     if peripheral.getType(name) == "redstone_relay" then
  21.       table.insert(redstoneRelays, peripheral.wrap(name))
  22.     end
  23.   end
  24.   if #redstoneRelays == 0 then
  25.     print("Warning: no relays found")
  26.   end
  27. end
  28.  
  29. -- CHECK INPUTS
  30. local function isLeverOn()
  31.   return redstone.getInput(leverSide)
  32. end
  33.  
  34. local function isAnyRelayPowered()
  35.   for _, relay in ipairs(redstoneRelays) do
  36.     if relay.getInput(relayRedstoneSide) then
  37.       return true
  38.     end
  39.   end
  40.   return false
  41. end
  42.  
  43. -- CONTROL
  44. local function controlReactor(leverOn, relayPowered)
  45.   local status = reactor.getStatus()
  46.  
  47.   if not leverOn then
  48.     -- Lever is OFF: force SCRAM
  49.     if status then
  50.       print("SCRAM: Lever OFF")
  51.       reactor.scram()
  52.     end
  53.   elseif relayPowered then
  54.     -- Lever is ON and relay active: activate reactor
  55.     if not status then
  56.       print("ACTIVATE: Redstone signal")
  57.       reactor.activate()
  58.     end
  59.   else
  60.     -- Lever is ON but no redstone: SCRAM
  61.     if status then
  62.       print("SCRAM: No redstone")
  63.       reactor.scram()
  64.     end
  65.   end
  66. end
  67.  
  68. -- MAIN LOOP
  69. local function main()
  70.   scanPeripherals()
  71.   if not reactor then return end
  72.  
  73.   while true do
  74.     local leverOn = isLeverOn()
  75.     local relayPowered = isAnyRelayPowered()
  76.  
  77.     print(string.format("Lever: %s | Redstone: %s | Reactor: %s",
  78.       leverOn and "ON" or "OFF",
  79.       relayPowered and "ON" or "OFF",
  80.       reactor.getStatus() and "ACTIVE" or "SCRAM"))
  81.  
  82.     controlReactor(leverOn, relayPowered)
  83.     sleep(loopDelay)
  84.   end
  85. end
  86.  
  87. main()
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement