Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local meBridge = peripheral.wrap("left") -- Connect to ME Bridge on the left side
- local monitor = peripheral.find("monitor") -- Find a connected monitor
- if not meBridge then
- print("Error: ME Bridge not found on the left 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
- -- Function to calculate storage usage
- function getStorageUsage()
- local itemUsage = meBridge.getUsedItemStorage() or 0
- local itemTotal = meBridge.getTotalItemStorage() or 1 -- Avoid division by zero
- local itemPercent = (itemUsage / itemTotal) * 100
- return {
- item = {
- used = itemUsage,
- free = itemTotal - itemUsage,
- total = itemTotal,
- percent = itemPercent
- }
- }
- 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: " .. string.format("%.1f", storage.item.used) .. " | Free: " .. string.format("%.1f", storage.item.free), colors.white)
- centerText(4, string.format("%.1f%% Used | %.1f%% Free", storage.item.percent, 100 - storage.item.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