Advertisement
bjmn55

Extreme Reactors CC Simple Turbine Control

Feb 7th, 2020
1,669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. -- Minecraft 1.12.2
  2. -- CC: Tweaked 1.86.0
  3. -- Extreme Reactors 1.12.2-0.4.5.67
  4.  
  5. -- This script expects to be connected to one or more Extreme Reactors Turbines
  6. -- either directly or via wired modem
  7.  
  8. -- get all connected turbines (directly or networked)
  9. turbines = {peripheral.find("BigReactors-Turbine")}
  10. local rotor_speed = 0
  11. local flow_rate = 0
  12.  
  13. -- make a way to easily set all turbines with the same value
  14. function setAllTurbines(setting_name, setting_val)
  15.     -- loop through all connected turbines loaded at the start of this script
  16.     for index, turbine in ipairs(turbines) do
  17.         -- set each turbine to what is requested
  18.         turbine[setting_name](setting_val)
  19.     end
  20. end
  21.  
  22. -- let the user know this script is running
  23. print('Automatic turbine control initiated')
  24.  
  25. -- let the user know we are activating all connected turbines
  26. print('Setting all connected turbines to active')
  27. -- activate all connected turbines
  28. setAllTurbines('setActive', true)
  29.  
  30. -- let the user know we are setting all turbines to dump excess liquid
  31. print('Setting all connected turbines to dump excess liquid')
  32. -- set all turbines to dump excess liquid
  33. setAllTurbines('setVentOverflow', '')
  34.  
  35. -- yay, an infinite loop :D (they are actually useful sometimes)
  36. while true do
  37.  
  38.     -- loop through all connected turbines loaded at the start of this script (this script will have to be restarted if new turbines are connected)
  39.     for index, turbine in ipairs(turbines) do
  40.  
  41.         -- get current turbine rotor speed
  42.         rotor_speed = turbine.getRotorSpeed()
  43.  
  44.         -- make sure current turbine rotor speed did not come back with nil, otherwise further testing to pointless
  45.         if rotor_speed ~= nil then
  46.  
  47.             -- check if the turbine is overspeed
  48.             if rotor_speed >= 1850 and turbine.getFluidFlowRateMax() > 5 then
  49.                 print('Turbine #'..(index+1)..' is overspeed, lowering fluid flow rate')
  50.                 -- if it is, reduce the max fluid flow rate to try to slow it down
  51.                 turbine.setFluidFlowRateMax(5)
  52.             end
  53.  
  54.             -- check if the turbine is back down from being overspeed
  55.             if rotor_speed < 1810 and turbine.getFluidFlowRateMax() < 2000 then
  56.                 print('Resetting fluid flow rate on turbine #'..(index+1)..' to max')
  57.                 -- if it is, set the max fluid flow rate back to normal
  58.                 turbine.setFluidFlowRateMax(2000)
  59.             end
  60.  
  61.             -- check if the turbine is at a good speed to engage the inductor
  62.             if rotor_speed >= 1800 and turbine.getInductorEngaged() == false then
  63.                 print('Turbine #'..(index+1)..' is full speed, re-engaging inductor')
  64.                 -- if it is, and the inductor is not engaged, engage it
  65.                 turbine.setInductorEngaged(true)
  66.             end
  67.  
  68.             -- check if the turbine is underspeed
  69.             if rotor_speed <= 1750 and turbine.getInductorEngaged() then
  70.                 print('Turbine #'..(index+1)..' is underspeed, disengaging inductor')
  71.                 -- if it is, disengage the inductor to try to speed it up
  72.                 turbine.setInductorEngaged(false)
  73.             end
  74.  
  75.         end -- end if not nil
  76.  
  77.     end -- end for
  78.  
  79.     -- sleep for a very short amount of time (100ms)
  80.     os.sleep(0.1)
  81.  
  82. end -- end while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement