Advertisement
Guest User

energy

a guest
Apr 7th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. power = peripheral.wrap("tile_blockcapacitorbank_name_1")
  2. mon = peripheral.wrap("right")
  3.  
  4. local maxPower = 0
  5. local curPower = 0
  6. local perPower = 0
  7. local emergency = 0
  8. monX, monY = mon.getSize()
  9.  
  10. function checkPower()
  11.   maxPower = power.getMaxEnergyStored()
  12.   curPower = power.getEnergyStored()
  13.   perPower = math.floor(((curPower/maxPower)*100)+0.5)
  14.   emergency = perPower  
  15. end
  16.  
  17. function writeMon()
  18.   mon.setBackgroundColor(colors.blue)
  19.   mon.clear()
  20.   mon.setCursorPos(1,1)
  21.  -- mon.write("Power")  
  22.   title = "  Power:" .. perPower .. "% Full "
  23.   center(title,1,colors.lightGray,colors.red)
  24.  
  25. end
  26.  
  27.  
  28. function center(text,line,backColor,textColor)
  29.   mon.setBackgroundColor(backColor)
  30.   mon.setTextColor(textColor)
  31.   length = ( string.len(text))
  32.   dif = math.floor(monX-length)
  33.   x = math.floor(dif/2)
  34.   mon.setCursorPos(x+1, line)
  35.   mon.write(text)
  36. end
  37.  
  38. function draw()
  39.   bar = math.floor(((curPower/maxPower)*(monX-2))+0.5)
  40.   mon.setCursorPos(2,monY-3)
  41.   mon.setBackgroundColor(colors.red)
  42.   mon.write(string.rep(" ", monX-2))
  43.  
  44.   mon.setCursorPos(2,monY-3)
  45.   mon.setBackgroundColor(colors.green)
  46.   mon.write(string.rep(" ", bar))
  47.      
  48. end
  49.  
  50.  
  51.  
  52. while true do
  53. checkPower()
  54. writeMon()
  55. draw()
  56. print(curPower .. "/" .. maxPower)
  57. sleep(1)
  58.  
  59. if emergency < 10 then
  60.   redstone.setOutput("back",true)
  61. elseif emergency > 50 then
  62.   redstone.setOutput("back",false)
  63. end
  64.  
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement