Advertisement
tbrixey

Basic Minecraft Reactor and Ender Cell Manager

Apr 23rd, 2021 (edited)
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. allNames = peripheral.getNames()
  2. monitor = peripheral.wrap("top")
  3.  
  4. monitor.setCursorPos(1, 1)
  5. monitor.clear()
  6. monX, monY = monitor.getSize()
  7. monitor.setTextScale(0.5)
  8. monitor.setTextColor(43)
  9. monitor.setCursorBlink(true)
  10. monitor.write("Starting...")
  11. monitor.setCursorPos(1, 2)
  12.  
  13. function write(msg)
  14.     curX, curY = monitor.getCursorPos()
  15.     monitor.write(msg)
  16.     if curY == monY then
  17.         monitor.scroll(1)
  18.         monitor.setCursorPos(1, monY)
  19.     else
  20.         monitor.setCursorPos(1, curY + 1)
  21.     end
  22. end
  23.  
  24. function getReactorName()
  25.     for x = 1, #allNames do
  26.         if string.match(allNames[x], "_Reactor_") then
  27.             return allNames[x]
  28.         end
  29.     end
  30. end
  31.  
  32. function getCellName()
  33.     for x = 1, #allNames do
  34.         if string.match(allNames[x], "ender_cell") then
  35.             return allNames[x]
  36.         end
  37.     end
  38. end
  39.  
  40. reactorName = getReactorName()
  41. enderCell = getCellName()
  42.  
  43. if reactorName == nil and enderCell == nil then
  44.     write("Can't find 'Bigger Reactors' reactor or 'Powah' Ender Cell")
  45.     exit()
  46. else
  47.     write("Found reactor and Cell")
  48. end
  49.  
  50. reactor = peripheral.wrap(reactorName)
  51. cell = peripheral.wrap(enderCell)
  52. prevCellLevel = cell.getEnergy() / cell.getEnergyCapacity()
  53.  
  54. function monitorPower()
  55.     while true do
  56.         currentRodPercent = reactor.getControlRod(0).level()
  57.         cellLevel = cell.getEnergy() / cell.getEnergyCapacity()
  58.         cellLevelRounded = cellLevel * 100
  59.         cellLevelRounded = math.floor(cellLevelRounded)
  60.         write("Battery level: " .. cellLevelRounded .. "%")
  61.  
  62.         if cellLevelRounded ~= 100 then
  63.             if cellLevel > prevCellLevel then
  64.                 if currentRodPercent == 99.9 then
  65.                     write("Can't push anymore")
  66.                 else
  67.                     reactor.setAllControlRodLevels(currentRodPercent + .1)
  68.                     write("Pushing rods, " .. currentRodPercent + .1 .. "%")
  69.                 end
  70.             else
  71.                 reactor.setAllControlRodLevels(currentRodPercent - 1)
  72.                 write("Pulling rods, " .. currentRodPercent - 1 .. "%")
  73.             end
  74.         else
  75.             reactor.setAllControlRodLevels(99.9)
  76.             write("Setting rods to 99.9%")
  77.         end
  78.  
  79.         prevCellLevel = cellLevel
  80.  
  81.         sleep(30)
  82.     end
  83. end
  84.  
  85. monitorPower()
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement