Advertisement
Thujed

storageUsage

Apr 24th, 2024 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. monitor = peripheral.find("monitor")
  2. width, height = monitor.getSize()
  3.  
  4. function getStorageStatistics()
  5. local chest = peripheral.find("functionalstorage:storage_controller")
  6.  
  7. local capacity = 0
  8. local size = 0
  9.  
  10. for slot, item in pairs(chest.list()) do
  11. size = size + item.count
  12. capacity = capacity + chest.getItemLimit(slot)
  13. end
  14.  
  15. return capacity, size
  16. end
  17.  
  18. function drawStatusBar(x, y, width, height, itemsPercent)
  19. paintutils.drawBox(x, y, width, y + 3, colors.white)
  20. paintutils.drawFilledBox(x + 1, y + 1, (width / 100) * itemsPercent, y + 2, colors.red)
  21. monitor.setBackgroundColor(colors.black)
  22. end
  23.  
  24. function main()
  25. term.redirect(monitor)
  26. monitor.setTextScale(1)
  27.  
  28. while 1 do
  29. monitor.setBackgroundColor(colors.black)
  30. local capacity, size = getStorageStatistics()
  31. local itemsPercent = size * 100 / capacity;
  32.  
  33. monitor.setCursorPos(1, 1)
  34. monitor.write(("Storage is %d%% full [%d | %d items]"):format(itemsPercent, size, capacity))
  35. drawStatusBar(1, 2, width, height, itemsPercent)
  36.  
  37.  
  38. end
  39. end
  40.  
  41. monitor.clear();
  42. main()
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement