Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local cells = {peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_10"),
  2.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_11"),
  3.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_12"),
  4.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_13"),
  5.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_14"),
  6.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_15"),
  7.   peripheral.wrap("tile_thermalexpansion_cell_reinforced_name_16")
  8.  
  9. }
  10.  
  11. local energyTable = {}
  12. local maxEnergyTable = {}
  13.  
  14. local reactor = peripheral.wrap("BigReactors-Reactor_1")
  15. local monitor = peripheral.wrap("monitor_1")
  16.  
  17. local enableReactorAt = 20
  18. local isReactorProcessing = false
  19.  
  20. function monitorClear()
  21.   monitor.setTextColor(colors.white)
  22.   monitor.clear()
  23.   monitor.setCursorPos(1,1)
  24. end
  25.  
  26. function monitorNewLine()
  27.   x, y = monitor.getCursorPos()
  28.   newY = y + 1
  29.   monitor.setCursorPos(1, newY)
  30. end
  31.  
  32. function writeTextTable(text)
  33.   monitorClear()
  34.   for i = 1, #text do
  35.     monitor.write(text[i])
  36.     monitorNewLine()
  37.   end
  38. end
  39.  
  40. function writeText(text, color)
  41.   monitor.setTextColor(color)
  42.   monitor.write(text)
  43.   monitorNewLine()
  44. end
  45.    
  46.  
  47. function monitorUpdate(totalEnergyStored, totalEnergyCapacity)
  48.   text = {}
  49.   strStart = "Energy Cell "
  50.   for i = 1, #energyTable do
  51.     text[i] = strStart .. tostring(i) .. " : " .. tostring(energyTable[i]) .. "/" .. tostring(maxEnergyTable[i])
  52.   end
  53.   writeTextTable(text)
  54.   textTotal = "Total Energy : " .. tostring(totalEnergyStored) .. " / " .. tostring(totalEnergyCapacity)
  55.   writeText(textTotal, colors.orange)
  56. end
  57.  
  58. function disableReactor()
  59.   reactor.setActive(false)
  60. end
  61.  
  62. function enableReactor()
  63.   reactor.setActive(true)
  64. end
  65.  
  66. function checkPower(totalEnergyStored, totalEnergyCapacity)
  67.   p = math.floor((totalEnergyStored / totalEnergyCapacity) * 100)
  68.   if isReactorProcessing then
  69.     if totalEnergyStored == totalEnergyCapacity then
  70.       disableReactor()
  71.     else
  72.       return
  73.     end
  74.   elseif p <= enableReactorAt then
  75.     enableReactor()
  76.   end
  77. end
  78.  
  79. while true do
  80.   totalEnergyStored = 0
  81.   totalEnergyCapacity = 0
  82.   for i = 1, #cells do
  83.     energyStored = cells[i].getEnergyStored()
  84.     maxEnergyStored = cells[i].getMaxEnergyStored()
  85.     energyTable[i] = energyStored
  86.     maxEnergyTable[i] = maxEnergyStored
  87.     totalEnergyStored = totalEnergyStored + tonumber(energyStored)
  88.     totalEnergyCapacity = totalEnergyCapacity + tonumber(maxEnergyStored)
  89.   end
  90.   monitorUpdate(totalEnergyStored, totalEnergyCapacity)
  91.   checkPower(totalEnergyStored, totalEnergyCapacity)
  92.   sleep(2)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement