NielsUtrecht

energy status

Sep 6th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. local monitor_side = "left"
  2. local modem_side = "back"
  3.  
  4. local cell_ids = {
  5.         "redstone_energy_cell_0",
  6.         "redstone_energy_cell_1",
  7.         "redstone_energy_cell_2",
  8.         "redstone_energy_cell_3"
  9. }
  10.  
  11. local net = peripheral.wrap(modem_side)
  12. local mon = peripheral.wrap(monitor_side)
  13. local cell = {}
  14.  
  15. for k,v in pairs(cell_ids) do
  16.         cell[k] = peripheral.wrap(v)
  17. end
  18.  
  19. mon.clear()
  20. --Adjust the textscale if you have a bigger/smaller monitor
  21. --Increments of 0.5
  22. mon.setTextScale(1)
  23. mon.setTextColor(512)
  24. mon.setCursorPos(1,1)
  25. mon.write("Energy status:")
  26.  
  27.  
  28.  
  29. while true do
  30.     local line = 1
  31.     local totalEnergy = 0
  32.     local totalMaxEnergy = 0
  33.     for k,v in pairs(cell) do
  34.             line=line+1
  35.             totalEnergy = totalEnergy + cell[k].getEnergyStored()
  36.             totalMaxEnergy = totalMaxEnergy + cell[k].getMaxEnergyStored()
  37.            
  38.             energy = math.floor(cell[k].getEnergyStored() / 100) / 10
  39.             percent = cell[k].getEnergyStored() / cell[k].getMaxEnergyStored()
  40.             maxEnergy = math.floor(cell[k].getMaxEnergyStored() / 100) / 10
  41.             percent = math.floor(percent * 1000) / 10
  42.            
  43.             energy = string.format("%3.1f", energy)
  44.             maxEnergy = string.format("%3.1f", maxEnergy)
  45.             percent = string.format("%3.1f", percent)
  46.             mon.setCursorPos(1,line)
  47.             mon.write(tostring(k) .. ":")
  48.             mon.setCursorPos(4,line)
  49.             mon.write(energy.."k")
  50.             mon.setCursorPos(13,line)
  51.             mon.write(percent.."%")        
  52.     end
  53.     line=line+1
  54.     energy = math.floor(totalEnergy / 100000) / 10
  55.     percent = math.floor(totalEnergy / totalMaxEnergy * 1000) / 10
  56.            
  57.     energy = string.format("%3.1f", energy)
  58.     percent = string.format("%3.1f", percent)
  59.            
  60.     mon.setCursorPos(4,line)
  61.     mon.write(energy.."M")
  62.     mon.setCursorPos(13,line)
  63.     mon.write(percent.."%")        
  64.    
  65.     os.sleep(3)
  66. end
Advertisement
Add Comment
Please, Sign In to add comment