Eldskogen

Untitled

Mar 11th, 2025
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 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() or 0
  58. local itemTotal = meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
  59. local fluidUsage = meBridge.getUsedFluidStorage() or 0
  60. local fluidTotal = meBridge.getTotalFluidStorage() or 1
  61. local gasUsage = meBridge.getUsedGasStorage() or 0
  62. local gasTotal = meBridge.getTotalGasStorage() or 1
  63. local energyStored = meBridge.getStoredPower() or 0
  64. local energyMax = meBridge.getMaxPower() or 1
  65.  
  66. return {
  67. item = {
  68. used = itemUsage,
  69. free = itemTotal - itemUsage,
  70. total = itemTotal,
  71. percent = (itemUsage / itemTotal) * 100
  72. },
  73. fluid = {
  74. used = fluidUsage,
  75. free = fluidTotal - fluidUsage,
  76. total = fluidTotal,
  77. percent = (fluidUsage / fluidTotal) * 100
  78. },
  79. gas = {
  80. used = gasUsage,
  81. free = gasTotal - gasUsage,
  82. total = gasTotal,
  83. percent = (gasUsage / gasTotal) * 100
  84. },
  85. energy = {
  86. stored = energyStored,
  87. max = energyMax,
  88. percent = (energyStored / energyMax) * 100
  89. }
  90. }
  91. end
  92.  
  93. -- Function to center text on the monitor
  94. function centerText(y, text, color)
  95. local w, _ = monitor.getSize()
  96. local x = math.floor((w - #text) / 2) + 1
  97. monitor.setCursorPos(x, y)
  98. if color then monitor.setTextColor(color) end
  99. monitor.write(text)
  100. monitor.setTextColor(colors.white) -- Reset text color
  101. end
  102.  
  103. -- Function to update the monitor display
  104. function updateMonitor()
  105. local storage = getStorageUsage()
  106. monitor.clear()
  107.  
  108. centerText(1, "Item Storage", colors.yellow)
  109. centerText(2, "---------------------", colors.yellow)
  110. centerText(3, "Used: " .. formatNumber(storage.item.used) .. " | Free: " .. formatNumber(storage.item.free), colors.white)
  111. centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
  112.  
  113. centerText(6, "Fluid Storage", colors.blue)
  114. centerText(7, "---------------------", colors.blue)
  115. centerText(8, "Used: " .. formatNumber(storage.fluid.used) .. " | Free: " .. formatNumber(storage.fluid.free), colors.white)
  116. centerText(9, string.format("%.1f%% Used | %.1f%% Free", storage.fluid.percent, 100 - storage.fluid.percent), colors.white)
  117.  
  118. centerText(11, "Gas Storage", colors.purple)
  119. centerText(12, "---------------------", colors.purple)
  120. centerText(13, "Used: " .. formatNumber(storage.gas.used) .. " | Free: " .. formatNumber(storage.gas.free), colors.white)
  121. centerText(14, string.format("%.1f%% Used | %.1f%% Free", storage.gas.percent, 100 - storage.gas.percent), colors.white)
  122.  
  123. centerText(16, "Energy Storage", colors.red)
  124. centerText(17, "---------------------", colors.red)
  125. centerText(18, "Stored: " .. formatNumber(storage.energy.stored) .. " / " .. formatNumber(storage.energy.max), colors.white)
  126. centerText(19, string.format("%.1f%% Capacity", storage.energy.percent), colors.white)
  127. end
  128.  
  129. -- Continuously update the monitor
  130. while true do
  131. updateMonitor()
  132. sleep(5) -- Updates every 5 seconds
  133. end
  134.  
Advertisement
Add Comment
Please, Sign In to add comment