Eldskogen

Untitled

Mar 11th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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.  
  24. local itemPercent = (itemUsage / itemTotal) * 100
  25.  
  26. return {
  27. item = {
  28. used = itemUsage,
  29. free = itemTotal - itemUsage,
  30. total = itemTotal,
  31. percent = itemPercent
  32. }
  33. }
  34. end
  35.  
  36. -- Function to center text on the monitor
  37. function centerText(y, text, color)
  38. local w, _ = monitor.getSize()
  39. local x = math.floor((w - #text) / 2) + 1
  40. monitor.setCursorPos(x, y)
  41. if color then monitor.setTextColor(color) end
  42. monitor.write(text)
  43. monitor.setTextColor(colors.white) -- Reset text color
  44. end
  45.  
  46. -- Function to update the monitor display
  47. function updateMonitor()
  48. local storage = getStorageUsage()
  49. monitor.clear()
  50.  
  51. centerText(1, "Item Storage", colors.yellow)
  52. centerText(2, "---------------------", colors.yellow)
  53. centerText(3, "Used: " .. string.format("%.1f", storage.item.used) .. " | Free: " .. string.format("%.1f", storage.item.free), colors.white)
  54. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  55. end
  56.  
  57. -- Continuously update the monitor
  58. while true do
  59. updateMonitor()
  60. sleep(5) -- Updates every 5 seconds
  61. end
  62.  
Advertisement
Add Comment
Please, Sign In to add comment