Advertisement
Grexxity

White Emc Monitor

Jan 30th, 2023 (edited)
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. local itemdb = {}
  2. local time = 0
  3. local startemc = nil
  4. local storage = peripheral.wrap( "left" )
  5. local mon = peripheral.find( "monitor" )
  6. mon.w, mon.h = mon.getSize()
  7.  
  8. local request = http.get( "https://gmod.club/scripts/cc/item_emc.json" )
  9. local json = request.readAll()
  10. itemdb = textutils.unserialiseJSON( json )
  11. request.close()
  12.  
  13. local input_item = "minecraft:blaze_rod"
  14.  
  15. local function clear()
  16. term.clear()
  17. mon.clear()
  18. term.setCursorPos( 5, 3 )
  19. term.setBackgroundColor( colors.white )
  20. mon.setTextColor( colors.black )
  21. mon.setTextScale( 2 )
  22. end
  23.  
  24. function formatTime( sec )
  25. return string.format( "%.2d:%.2d:%.2d", sec / ( 60 * 60 ), sec / 60 % 60, sec % 60 )
  26. end
  27.  
  28. function comma( n )
  29. return tostring( math.floor( n ) ):reverse():gsub( "(%d%d%d)","%1," ):gsub( ",(%-?)$","%1" ):reverse()
  30. end
  31.  
  32. clear()
  33. term.redirect( mon )
  34.  
  35. while true do
  36.  
  37. clear()
  38.  
  39. local emc = 0
  40. local amount = 0
  41.  
  42. for slot, item in pairs( storage.list() ) do
  43. if item.name ~= input_item then
  44. amount = amount + item.count
  45. local stored = itemdb[item.name .. "|" .. item.damage]
  46. if stored then
  47. emc = emc + ( item.count * stored )
  48. end
  49. end
  50. end
  51.  
  52. mon.setTextColor( colors.black )
  53. mon.setCursorPos( 8, 1 )
  54. mon.write( "EMC Monitor" )
  55.  
  56. mon.setCursorPos( 5, 3 )
  57. mon.write( "EMC: " .. comma( emc ) )
  58. if startemc == nil then startemc = emc end
  59.  
  60. local gained = emc - startemc
  61. local emcrate = math.floor( gained / time ) * 60
  62. if gained < 0 then os.reboot() end
  63. mon.setCursorPos( 5, 4 )
  64. mon.write( "EMC/m: " .. comma( emcrate ) )
  65.  
  66. mon.setCursorPos( 5, 5 )
  67. mon.write( "Time: " .. formatTime( time ) )
  68.  
  69. mon.setCursorPos( 5, 6 )
  70. mon.write( "Amount: " .. comma( amount ) )
  71.  
  72. time = time + 1
  73.  
  74. sleep( 1 )
  75.  
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement