XSiggeManx

Draconic Reactor ComputerCraft integration

Dec 11th, 2020 (edited)
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. inGate = peripheral.wrap("flux_gate_1") -- Edit to the name of your input flux gate.
  2. outGate = peripheral.wrap("flux_gate_0") -- Edit to the name of your output flux gate.
  3. otherComputerId = 15 -- Change this number to the other computers' ID. You can get the ID by typing "id" into the terminal.
  4.  
  5. reactor = peripheral.find("draconic_reactor")
  6. if reactor == nil then
  7. print("No reactor found!")
  8. return
  9. end
  10. info = {}
  11. local modemCount = 0
  12. for i,v in pairs(redstone.getSides()) do
  13. if peripheral.getType(v) == "modem" then
  14. rednet.open(v)
  15. modemCount = modemCount + 1
  16. end
  17. end
  18. if modemCount < 2 then
  19. print("You need at least one wireless/ender modem and another wired modem to connect the flux gates with.")
  20. return
  21. end
  22. local temp
  23. local shield
  24. local sat
  25. local fuel
  26. local status
  27.  
  28. local inputRate
  29. local inputMult = 1.015
  30.  
  31. local outputRate
  32. local targetTemp = 8000
  33. local outputMult = 3
  34.  
  35. safetyOverride = false
  36.  
  37. function mainStuff()
  38. while true do
  39. info = reactor.getReactorInfo()
  40. temp = info.temperature
  41. shield = math.ceil(info.fieldStrength / info.maxFieldStrength * 1000) / 1000
  42. sat = math.ceil(info.energySaturation / info.maxEnergySaturation * 1000) / 1000
  43. fuel = math.ceil(info.fuelConversion / info.maxFuelConversion * 10000) / 10000
  44. status = info.status
  45. rednet.send(otherComputerId, info)
  46.  
  47. -- Get the output RF/t speed
  48. if shield < 0.02 then
  49. outputMult = 10
  50. elseif shield >= 0.02 and shield < 0.1 then
  51. outputMult = 7
  52. elseif shield >= 0.1 and shield < 0.4 then
  53. outputMult = 3.5
  54. else
  55. outputMult = 2
  56. end
  57. if temp <= targetTemp + 1 then
  58. outputRate = info.generationRate * outputMult * (1.1 - (temp / targetTemp))
  59. else
  60. outputRate = info.generationRate * 0.96
  61. end
  62.  
  63. inputRate = info.fieldDrainRate * inputMult * (1 - shield)
  64.  
  65. safetyCheck()
  66.  
  67. if status == "running" and fuel > 0.8 then
  68.         reactor.stopReactor()
  69.     elseif status == "running" and safetyOverride == false then
  70.         if safetyOverride == false then
  71.         inGate.setSignalLowFlow(inputRate)
  72.         outGate.setSignalLowFlow(outputRate)
  73.     end
  74.     elseif status == "cooling" or coreStatus == "stopping" then
  75.         outGate.setSignalLowFlow(0)
  76.     if temp < 2000 then
  77.         inGate.setSignalLowFlow(0)
  78.     else
  79.         inGate.setSignalLowFlow(500000)
  80.     end
  81.     elseif status == "warming_up" then
  82.         inGate.setSignalLowFlow(1000000)
  83.         outGate.setSignalLowFlow(0)
  84. end
  85.  
  86. sleep(0)
  87. end
  88. end
  89.  
  90. function safetyCheck()
  91.     if ( shield < 0.005 or temp >= 8200 or sat <= .05 ) then
  92.         if safetyOverride == false and temp >= 2000 then
  93.             safetyOverride = true
  94.         end
  95.        
  96.         if temp >= 2000 then
  97.             inGate.setSignalLowFlow(500000)
  98.             outGate.setSignalLowFlow(0)
  99.         end
  100.     else
  101.  
  102.         if (shield > .1 and temp < 8000 and safetyOverride == true ) then        
  103.             safetyOverride = false
  104.         end
  105.     end
  106.    
  107.     if temp >= 2500 and status == "running" then
  108.         reactor.setFailSafe(true)
  109.     elseif status == "warming_up" then
  110.         reactor.setFailSafe(false)
  111.     end
  112.     return
  113. end
  114.  
  115. function redNetReceive()
  116. while true do
  117. id, msg = rednet.receive()
  118. if id == otherComputerId then
  119. if msg == "chargeReactor" and (info.status == "cold" or info.status == "cooling") then
  120. reactor.chargeReactor()
  121. end
  122. if msg == "activateReactor" and (info.status == "warming_up" or info.status == "stopping") and info.temperature >= 2000 then
  123. reactor.activateReactor()
  124. end
  125. if msg == "stopReactor" and (info.status == "warming_up" or info.status == "running") then
  126. reactor.stopReactor()
  127. end
  128. end
  129. sleep(0)
  130. end
  131. end
  132.  
  133. parallel.waitForAll(mainStuff, redNetReceive)
  134.  
  135. --setFailSafe(bool)
  136.  
  137. -- cold warming_up running stopping cooling
  138. -- beyond_hope
Add Comment
Please, Sign In to add comment