Eldskogen

Untitled

Mar 11th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. local sides = {"top", "bottom", "left", "right", "front", "back"}
  2. local meBridge = nil
  3. local monitor = peripheral.find("monitor") -- Find a connected monitor
  4. local speaker = peripheral.find("speaker") -- Find a connected speaker
  5.  
  6. -- Function to find the ME Bridge on any side
  7. for _, side in ipairs(sides) do
  8. if peripheral.getType(side) == "meBridge" then
  9. meBridge = peripheral.wrap(side)
  10. print("ME Bridge found on: " .. side)
  11. break
  12. end
  13. end
  14.  
  15. if not meBridge then
  16. print("Error: ME Bridge not found on any side!")
  17. return
  18. else
  19. print("ME Bridge successfully detected!")
  20. end
  21.  
  22. if not monitor then
  23. print("Error: No monitor found!")
  24. return
  25. else
  26. print("Monitor successfully detected!")
  27. monitor.setTextScale(1) -- Set text scale for better visibility
  28. end
  29.  
  30. -- Play boot sound if speaker is present
  31. if speaker then
  32. local file = fs.open("123.dfpwm", "rb")
  33. if file then
  34. local decoder = require("cc.audio.dfpwm").make_decoder()
  35. local chunk = file.readAll()
  36. file.close()
  37.  
  38. speaker.playAudio(decoder(chunk))
  39. else
  40. print("Boot sound file '123.dfpwm' not found.")
  41. end
  42. end
  43.  
  44. -- Function to format numbers with commas
  45. function formatNumber(num)
  46. local formatted = tostring(num)
  47. local k = 3
  48. while k < #formatted do
  49. formatted = formatted:sub(1, #formatted - k) .. "," .. formatted:sub(#formatted - k + 1)
  50. k = k + 4
  51. end
  52. return formatted
  53. end
  54.  
  55. -- Function to calculate storage usage
  56. function getStorageUsage()
  57. local itemUsage = meBridge.getUsedItemStorage and meBridge.getUsedItemStorage() or 0
  58. local itemTotal = meBridge.getTotalItemStorage and meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
  59. local fluidUsage = meBridge.getUsedFluidStorage and meBridge.getUsedFluidStorage() or 0
  60. local fluidTotal = meBridge.getTotalFluidStorage and meBridge.getTotalFluidStorage() or 1
  61.  
  62. return {
  63. item = {
  64. used = itemUsage,
  65. free = itemTotal - itemUsage,
  66. total = itemTotal,
  67. percent = (itemUsage / itemTotal) * 100
  68. },
  69. fluid = {
  70. used = fluidUsage,
  71. free = fluidTotal - fluidUsage,
  72. total = fluidTotal,
  73. percent = (fluidUsage / fluidTotal) * 100
  74. }
  75. }
  76. end
  77.  
  78. -- Function to center text on the monitor
  79. function centerText(y, text, color)
  80. local w, _ = monitor.getSize()
  81. local x = math.floor((w - #text) / 2) + 1
  82. monitor.setCursorPos(x, y)
  83. if color then monitor.setTextColor(color) end
  84. monitor.write(text)
  85. monitor.setTextColor(colors.white) -- Reset text color
  86. end
  87.  
  88. -- Function to update the monitor display
  89. function updateMonitor()
  90. local storage = getStorageUsage()
  91. monitor.clear()
  92.  
  93. centerText(1, "Item Storage", colors.yellow)
  94. centerText(2, "---------------------", colors.yellow)
  95. centerText(3, "Used: " .. formatNumber(storage.item.used) .. " | Free: " .. formatNumber(storage.item.free), colors.white)
  96. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  97.  
  98. centerText(6, "Fluid Storage", colors.blue)
  99. centerText(7, "---------------------", colors.blue)
  100. centerText(8, "Used: " .. formatNumber(storage.fluid.used) .. " | Free: " .. formatNumber(storage.fluid.free), colors.white)
  101. centerText(9, string.format("%.1f%% Used | %.1f%% Free", storage.fluid.percent, 100 - storage.fluid.percent), colors.white)
  102. end
  103.  
  104. -- Continuously update the monitor
  105. while true do
  106. updateMonitor()
  107. sleep(5) -- Updates every 5 seconds
  108. end
  109.  
Add Comment
Please, Sign In to add comment