MuChT007

FTB Small steam control WIP

Jan 31st, 2022 (edited)
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1. --Setup
  2. --local modem = peripheral.wrap("left")
  3. local capacitorSide = "top"
  4. local cellType = 1 --basic,normal,vibrant
  5. local cells = 8
  6. local rsOutSide = "bottom"
  7. local boiler = {colors.orange,colors.red,colors.blue}
  8. local rsOut = 0
  9. local newRsOut = 0
  10. local boilerOn = {false,false,false}
  11. --local txChannel = 1400
  12. --local rxChannel = 1410
  13. local mon = peripheral.wrap("back")
  14.  
  15. for i = 1,3 do
  16.     rsOut = colors.combine(rsOut, boiler[i] )
  17.     newRsOut = rsOut
  18. end
  19. redstone.setBundledOutput(rsOutSide, rsOut)
  20. --Variables
  21. local cellsCapacities = {1000000,5000000,25000000}
  22. local cellCapacity = (cellsCapacities[cellType]) * (cells)
  23. local capacitor_1 = peripheral.wrap(capacitorSide)
  24. local energyLevelOld = 0
  25. mon.setTextScale(0.5)
  26. x, y = mon.getSize()
  27.  
  28. --Functions
  29. function drawCentered(line, text)
  30.  mon.setCursorPos((x - string.len(text))/ 2, line)
  31.  mon.write(text)
  32. end
  33.  
  34. function drawAcross(line, char)
  35.     mon.setCursorPos(1, line)
  36.     for i = 1,  x do
  37.         mon.write(char)
  38.     end
  39. end
  40.  
  41. function drawPcBar(line, char, size)
  42.     oldColor = mon.getTextColor()
  43.     mon.setCursorPos(1, line)
  44.     mon.clearLine()
  45.     maxLengt = math.ceil(x * 0.8)
  46.     sizeB = math.ceil(size*maxLengt/100)
  47.     mon.setTextColor( colors.white )
  48.     mon.setCursorPos(1, line)
  49.     mon.write("[")
  50.     mon.setCursorPos(2, line)
  51.     if size < 25 then newColor = colors.red end
  52.     if ((size < 75) and (size > 25)) then newColor = colors.orange end
  53.     if size > 75 then newColor = colors.lime end
  54.     mon.setTextColor( newColor )
  55.     for i = 1,  sizeB do
  56.         mon.write(char)
  57.     end
  58.     mon.setCursorPos((maxLengt+2), line)
  59.     mon.setTextColor( colors.white )
  60.     mon.write("]   "..size.."%")
  61.     mon.setTextColor( oldColor )
  62. end
  63.  
  64. function showRatio(line, num1, num2)
  65.     oldColor = mon.getTextColor()
  66.     mon.setCursorPos(1, line)
  67.     mon.clearLine()
  68.     mon.setTextColor( colors.white )
  69.     mon.write(num1.."/"..num2)
  70.    
  71. end
  72.  
  73. function resetNewRsOut ()
  74.     for i = 1,3 do
  75.         newRsOut = colors.combine(newRsOut, boiler[i] )
  76.     end
  77. end
  78.  
  79. --body
  80.  
  81. --prepare screen
  82.  
  83. mon.clear()
  84. mon.setTextColor( colors.white )
  85. mon.setBackgroundColor(colors.gray)
  86. drawCentered(2, "Power storage monitoring")
  87. drawAcross(3, "=")
  88. --Steam production
  89. drawAcross(6, "-")
  90. mon.setTextColor(colors.yellow)
  91. mon.setCursorPos(5,7)
  92. mon.write("Steam production:")
  93. --Power storage
  94. mon.setTextColor( colors.white )
  95. drawAcross(20, "-")
  96. mon.setTextColor(colors.yellow)
  97. mon.setCursorPos(5,21)
  98. mon.write("RF storage:")
  99.  
  100.  
  101. while true do
  102.     --Get the capacitor datas
  103.     energyLevel = capacitor_1.getEnergyStored()
  104.     energyLevel = (energyLevel) * (cells)
  105.     local pcCap = (energyLevel*100)/cellCapacity --RF stored in %
  106.     pcCap = math.ceil(pcCap)
  107.    
  108.     drawPcBar(22, "#", pcCap)
  109.     showRatio(23, energyLevel, cellCapacity)
  110.  
  111.     if pcCap < 90 then
  112.         boilerOn[1] = true
  113.     else
  114.         boilerOn[1] = false
  115.     end
  116.    
  117.     if pcCap < 75 then
  118.         boilerOn[2] = true
  119.     else
  120.         boilerOn[2] = false
  121.     end
  122.    
  123.     if pcCap < 50 then
  124.         boilerOn[3] = true
  125.     else
  126.         boilerOn[3] = false
  127.     end
  128.  
  129.    
  130.     for i = 1,3 do
  131.         if boilerOn[i] == true then
  132.             newRsOut = colors.subtract(colors.combine(newRsOut), boiler[i])
  133.         end
  134.     end
  135.    
  136.     if newRsOut == rsOut then
  137.         resetNewRsOut ()
  138.     else
  139.         rsOut = newRsOut
  140.         redstone.setBundledOutput(rsOutSide, rsOut)
  141.     end
  142.    
  143.  
  144.    
  145.     sleep(math.random(0,10))
  146.  
  147. end
Add Comment
Please, Sign In to add comment