Eldskogen

Untitled

Mar 11th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. local meBridge = peripheral.wrap("left") -- Connect to ME Bridge on the left side
  2. local monitor = peripheral.find("monitor") -- Find a connected monitor
  3.  
  4. if not meBridge then
  5. print("Error: ME Bridge not found on the left side!")
  6. return
  7. else
  8. print("ME Bridge successfully detected!")
  9. end
  10.  
  11. if not monitor then
  12. print("Error: No monitor found!")
  13. return
  14. else
  15. print("Monitor successfully detected!")
  16. monitor.setTextScale(1) -- Set text scale for better visibility
  17. end
  18.  
  19. -- Function to calculate storage usage
  20. function getStorageUsage()
  21. local itemUsage = meBridge.getUsedItemStorage() or 0
  22. local itemTotal = meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
  23. local itemBytesUsed = meBridge.getUsedItemBytes() or 0
  24. local itemBytesTotal = meBridge.getTotalItemBytes() or 1
  25.  
  26. local itemPercent = (itemUsage / itemTotal) * 100
  27. local itemBytesPercent = (itemBytesUsed / itemBytesTotal) * 100
  28.  
  29. return {
  30. item = {
  31. used = itemUsage,
  32. free = itemTotal - itemUsage,
  33. total = itemTotal,
  34. percent = itemPercent,
  35. bytesUsed = itemBytesUsed,
  36. bytesFree = itemBytesTotal - itemBytesUsed,
  37. bytesTotal = itemBytesTotal,
  38. bytesPercent = itemBytesPercent
  39. }
  40. }
  41. end
  42.  
  43. -- Function to center text on the monitor
  44. function centerText(y, text, color)
  45. local w, _ = monitor.getSize()
  46. local x = math.floor((w - #text) / 2) + 1
  47. monitor.setCursorPos(x, y)
  48. if color then monitor.setTextColor(color) end
  49. monitor.write(text)
  50. monitor.setTextColor(colors.white) -- Reset text color
  51. end
  52.  
  53. -- Function to update the monitor display
  54. function updateMonitor()
  55. local storage = getStorageUsage()
  56. monitor.clear()
  57.  
  58. centerText(1, "Item Storage", colors.yellow)
  59. centerText(2, "---------------------", colors.yellow)
  60. centerText(3, "Used: " .. string.format("%.1f", storage.item.used) .. " | Free: " .. string.format("%.1f", storage.item.free), colors.white)
  61. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  62.  
  63. centerText(6, "Storage in Bytes", colors.lightGray)
  64. centerText(7, "---------------------", colors.lightGray)
  65. centerText(8, "Used: " .. string.format("%.1f", storage.item.bytesUsed) .. "B | Free: " .. string.format("%.1f", storage.item.bytesFree) .. "B", colors.white)
  66. centerText(9, string.format("%.1f%% Used | %.1f%% Free", storage.item.bytesPercent, 100 - storage.item.bytesPercent), colors.white)
  67. end
  68.  
  69. -- Continuously update the monitor
  70. while true do
  71. updateMonitor()
  72. sleep(5) -- Updates every 5 seconds
  73. end
  74.  
Advertisement
Add Comment
Please, Sign In to add comment