Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local meBridge = nil
- local monitor = peripheral.find("monitor") -- Find a connected monitor
- local speaker = peripheral.find("speaker") -- Find a connected speaker
- -- Function to find the ME Bridge on any side
- for _, side in ipairs(sides) do
- if peripheral.getType(side) == "meBridge" then
- meBridge = peripheral.wrap(side)
- print("ME Bridge found on: " .. side)
- break
- end
- end
- if not meBridge then
- print("Error: ME Bridge not found on any side!")
- return
- else
- print("ME Bridge successfully detected!")
- end
- if not monitor then
- print("Error: No monitor found!")
- return
- else
- print("Monitor successfully detected!")
- monitor.setTextScale(1) -- Set text scale for better visibility
- end
- -- Play boot sound if speaker is present
- if speaker then
- local file = fs.open("123.dfpwm", "rb")
- if file then
- local decoder = require("cc.audio.dfpwm").make_decoder()
- local chunk = file.readAll()
- file.close()
- speaker.playAudio(decoder(chunk))
- else
- print("Boot sound file '123.dfpwm' not found.")
- end
- end
- -- Function to format numbers with commas
- function formatNumber(num)
- local formatted = tostring(num)
- local k = 3
- while k < #formatted do
- formatted = formatted:sub(1, #formatted - k) .. "," .. formatted:sub(#formatted - k + 1)
- k = k + 4
- end
- return formatted
- end
- -- Function to calculate storage usage
- function getStorageUsage()
- local itemUsage = meBridge.getUsedItemStorage and meBridge.getUsedItemStorage() or 0
- local itemTotal = meBridge.getTotalItemStorage and meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
- local fluidUsage = meBridge.getUsedFluidStorage and meBridge.getUsedFluidStorage() or 0
- local fluidTotal = meBridge.getTotalFluidStorage and meBridge.getTotalFluidStorage() or 1
- return {
- item = {
- used = itemUsage,
- free = itemTotal - itemUsage,
- total = itemTotal,
- percent = (itemUsage / itemTotal) * 100
- },
- fluid = {
- used = fluidUsage,
- free = fluidTotal - fluidUsage,
- total = fluidTotal,
- percent = (fluidUsage / fluidTotal) * 100
- }
- }
- end
- -- Function to center text on the monitor
- function centerText(y, text, color)
- local w, _ = monitor.getSize()
- local x = math.floor((w - #text) / 2) + 1
- monitor.setCursorPos(x, y)
- if color then monitor.setTextColor(color) end
- monitor.write(text)
- monitor.setTextColor(colors.white) -- Reset text color
- end
- -- Function to update the monitor display
- function updateMonitor()
- local storage = getStorageUsage()
- monitor.clear()
- centerText(1, "Item Storage", colors.yellow)
- centerText(2, "---------------------", colors.yellow)
- centerText(3, "Used: " .. formatNumber(storage.item.used) .. " | Free: " .. formatNumber(storage.item.free), colors.white)
- centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.percent), colors.white)
- centerText(6, "Fluid Storage", colors.blue)
- centerText(7, "---------------------", colors.blue)
- centerText(8, "Used: " .. formatNumber(storage.fluid.used) .. " | Free: " .. formatNumber(storage.fluid.free), colors.white)
- centerText(9, string.format("%.1f%% Used | %.1f%% Free", storage.fluid.percent, 100 - storage.fluid.percent), colors.white)
- end
- -- Continuously update the monitor
- while true do
- updateMonitor()
- sleep(5) -- Updates every 5 seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment