Eldskogen

Untitled

Mar 11th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 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 in chunks
  32. if speaker then
  33. local file = fs.open("123.dfpwm", "rb")
  34. if file then
  35. local decoder = dfpwm.make_decoder()
  36. local buffer = {}
  37.  
  38. print("Playing boot sound...")
  39.  
  40. while true do
  41. local chunk = file.read(2048) -- Read small chunks
  42. if not chunk then break end
  43. table.insert(buffer, chunk)
  44. end
  45. file.close()
  46.  
  47. -- Play the sound in chunks
  48. for _, chunk in ipairs(buffer) do
  49. local decoded = decoder(chunk)
  50. speaker.playAudio(decoded)
  51. sleep(0) -- Prevent "Too long without yielding" error
  52. end
  53.  
  54. print("Boot sound finished playing.")
  55. else
  56. print("Boot sound file '123.dfpwm' not found.")
  57. end
  58. end
  59.  
  60. -- Function to format numbers with commas
  61. function formatNumber(num)
  62. local formatted = tostring(num)
  63. local k = 3
  64. while k < #formatted do
  65. formatted = formatted:sub(1, #formatted - k) .. "," .. formatted:sub(#formatted - k + 1)
  66. k = k + 4
  67. end
  68. return formatted
  69. end
  70.  
  71. -- Function to calculate storage usage
  72. function getStorageUsage()
  73. local itemUsage = meBridge.getUsedItemStorage and meBridge.getUsedItemStorage() or 0
  74. local itemTotal = meBridge.getTotalItemStorage and meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
  75. local fluidUsage = meBridge.getUsedFluidStorage and meBridge.getUsedFluidStorage() or 0
  76. local fluidTotal = meBridge.getTotalFluidStorage and meBridge.getTotalFluidStorage() or 1
  77.  
  78. return {
  79. item = {
  80. used = itemUsage,
  81. free = itemTotal - itemUsage,
  82. total = itemTotal,
  83. percent = (itemUsage / itemTotal) * 100
  84. },
  85. fluid = {
  86. used = fluidUsage,
  87. free = fluidTotal - fluidUsage,
  88. total = fluidTotal,
  89. percent = (fluidUsage / fluidTotal) * 100
  90. }
  91. }
  92. end
  93.  
  94. -- Function to center text on the monitor
  95. function centerText(y, text, color)
  96. local w, _ = monitor.getSize()
  97. local x = math.floor((w - #text) / 2) + 1
  98. monitor.setCursorPos(x, y)
  99. if color then monitor.setTextColor(color) end
  100. monitor.write(text)
  101. monitor.setTextColor(colors.white) -- Reset text color
  102. end
  103.  
  104. -- Function to update the monitor display
  105. function updateMonitor()
  106. local storage = getStorageUsage()
  107. monitor.clear()
  108.  
  109. centerText(1, "Item Storage", colors.yellow)
  110. centerText(2, "---------------------", colors.yellow)
  111. centerText(3, "Used: " .. formatNumber(storage.item.used) .. " | Free: " .. formatNumber(storage.item.free), colors.white)
  112. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  113.  
  114. centerText(6, "Fluid Storage", colors.blue)
  115. centerText(7, "---------------------", colors.blue)
  116. centerText(8, "Used: " .. formatNumber(storage.fluid.used) .. " | Free: " .. formatNumber(storage.fluid.free), colors.white)
  117. centerText(9, string.format("%.1f%% Used | %.1f%% Free", storage.fluid.percent, 100 - storage.fluid.percent), colors.white)
  118. end
  119.  
  120. -- Continuously update the monitor
  121. while true do
  122. updateMonitor()
  123. sleep(5) -- Updates every 5 seconds
  124. end
  125.  
Advertisement
Add Comment
Please, Sign In to add comment