Shadows_Player

Matrix Energy

Jan 7th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. power = peripheral.wrap("back")
  2. mon = peripheral.wrap("top")
  3. wmod= peripheral.wrap("left")
  4.  
  5. local maxPower = 0
  6. local curPower = 0
  7. local perPower = 0
  8. local outPower = 0
  9. local inpPower = 0
  10. local capPower = 0
  11. local warning = 10
  12. monX,monY = mon.getSize()
  13.  
  14.    
  15. function getMaxEnergy(cube)
  16.     return cube.getMaxEnergy() * 0.4
  17. end
  18.  
  19. function getEnergy(cube)
  20.     return cube.getEnergy() * 0.4
  21. end
  22.  
  23. function getOutput(cube)
  24.     return cube.getOutput() * 0.4
  25. end
  26. function getInput(cube)
  27.     return cube.getInput() * 0.4
  28. end
  29.  
  30. function per()
  31.     mon.setBackgroundColor(colors.black)
  32.     perPower = math.floor(((getEnergy(power)/getMaxEnergy(power))*100+0.4))
  33.     mon.setCursorPos(1,1)
  34.     mon.write(" Power: " .. perPower .. "%")
  35. end
  36.  
  37. function shorthand(number)
  38.     assert(type(number) == "number", "Type number cannot be a "..type(number))
  39.     local letters = {'rf', 'Krf', 'Mrf', 'Grf', 'Trf', 'QDrf', 'QTrf'}
  40.     local log = math.max(math.log10(number), 0)
  41.     local pwr = math.floor(log / 3)
  42.     assert(pwr + 1 <= #letters, "Number too big - we don't have enough suffixes")
  43.     return ("%.3g%s"):format(number / 1000^pwr, letters[pwr + 1])
  44. end
  45.  
  46. function writeMon()
  47.   mon.setBackgroundColor(colors.black)
  48.   mon.clear()
  49.   mon.setCursorPos(1,2)
  50.   mon.write(" Currrent: ")
  51.   mon.write(shorthand(getEnergy(power)))
  52.   mon.setCursorPos(1,3)
  53.   mon.write(" Input: ")
  54.   mon.write(shorthand(getInput(power)))
  55.   mon.setCursorPos(1,4)
  56.   mon.write(" Output: ")
  57.    mon.write(shorthand(getOutput(power)))
  58.  
  59. end
  60.  
  61. function drawbar()
  62.    sendmsg = perPower .."%Full"
  63.    teste = {cur = getEnergy(power), maxe = getMaxEnergy(power), per = sendmsg, scur = shorthand(getEnergy(power))}  
  64.    wmod.closeAll()
  65.    wmod.open(1)
  66.    wmod.transmit(1, 1, teste)
  67. end
  68.  
  69. function red()
  70.   if perPower < 30 then
  71.     redstone.setOutput("right",true)
  72.   else
  73.     redstone.setOutput("right",false)
  74.   end
  75. end
  76. while true do
  77. writeMon()
  78. per()
  79. drawbar()
  80. red()
  81. print(shorthand(getEnergy(power)) .. "/" .. shorthand(getMaxEnergy(power)))
  82. sleep(0.5)
  83. end
  84.  
Add Comment
Please, Sign In to add comment