Eldskogen

Untitled

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