Happymonkey4

energyCubeMonitor_1.1

Jan 21st, 2021 (edited)
1,499
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Initialize all the cubes and the monitor
  2. cube = {}
  3.  
  4. cube[0] = peripheral.wrap("mekanism:ultimate_energy_cube_0")
  5. cube[1] = peripheral.wrap("mekanism:ultimate_energy_cube_1")
  6. cube[2] = peripheral.wrap("mekanism:ultimate_energy_cube_2")
  7. cube[3] = peripheral.wrap("mekanism:ultimate_energy_cube_3")
  8. cube[4] = peripheral.wrap("mekanism:ultimate_energy_cube_4")
  9. cube[5] = peripheral.wrap("mekanism:ultimate_energy_cube_5")
  10. cube[6] = peripheral.wrap("mekanism:ultimate_energy_cube_6")
  11. cube[7] = peripheral.wrap("mekanism:ultimate_energy_cube_7")
  12. cube[8] = peripheral.wrap("mekanism:ultimate_energy_cube_8")
  13. cube[9] = peripheral.wrap("mekanism:ultimate_energy_cube_9")
  14. cube[10] = peripheral.wrap("mekanism:ultimate_energy_cube_10")
  15. cube[11] = peripheral.wrap("mekanism:ultimate_energy_cube_11")
  16. mon = peripheral.wrap("top")
  17.  
  18. -- Initialize current Energy array
  19. currentE = {}
  20.  
  21. for i=0,11 do currentE[i] = -1 end
  22.  
  23. mon.setTextScale(1)
  24.  
  25. -- main loop
  26. while true do
  27.     for i=0,11 do
  28.         currentCube = cube[i]
  29.         cubeE = currentCube.getEnergy()
  30.  
  31.         -- Check if current cube should be updated
  32.         if cubeE ~= currentE[i] then
  33.             mon.setCursorPos(1,i+1)
  34.             mon.clearLine()
  35.             mon.setTextColor(colors.white)
  36.  
  37.             if i < 9 then
  38.                 mon.write(string.format("CUBE %d:  ",i+1))
  39.             else
  40.                 mon.write(string.format("CUBE %d: ",i+1))
  41.             end
  42.            
  43.             -- determine the color if the text base on the amount of charge left in the cube
  44.             if cubeE < 1000000 then
  45.                 mon.setTextColor(colors.yellow)
  46.             elseif cubeE < 50000 then
  47.                 mon.setTextColor(colors.red)
  48.             else
  49.                 mon.setTextColor(colors.green)
  50.             end
  51.            
  52.             mon.write(string.format("%.2f",cubeE/1000000))
  53.             mon.setTextColor(colors.white)
  54.             mon.write(" M")
  55.             currentE[i] = cubeE
  56.         end
  57.     end
  58.  
  59.     sleep(5)
  60. end
RAW Paste Data