Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function round(n)
- return math.floor(n + 0.5)
- end
- local function formatNumberWithCommas(n)
- local formatted = tostring(n):reverse():gsub("(%d%d%d)", "%1,"):reverse()
- return formatted:match("^,") and formatted:sub(2) or formatted
- end
- local function getItemDetails(itemName)
- local item = ME.getItem({ name = itemName }) -- Ensure correct item ID
- if item then
- print("\n" .. item.displayName .. " details:") -- Print item display name
- for key, value in pairs(item) do
- print(key .. ": " .. tostring(value)) -- Print all key-value pairs
- end
- else
- print(itemName .. " not found in the system.")
- end
- end
- local function getCellInfo()
- local cells = ME.listCells() -- Get storage cells
- if not cells or #cells == 0 then
- print("No storage cells found.")
- return
- end
- print("\nStorage Cells Info:")
- for index, cell in ipairs(cells) do
- print("\nCell #" .. index)
- for key, value in pairs(cell) do
- print(" " .. key .. ": " .. tostring(value))
- end
- end
- end
- local function getCellItemStorage()
- local cells = ME.listCells() -- Get storage cells
- if not cells or #cells == 0 then
- print("No storage cells found.")
- return 0 -- Return 0 if no cells exist
- end
- local totalStorage = 0
- for _, cell in ipairs(cells) do
- if cell.type == "item" then -- Only sum item storage cells
- totalStorage = totalStorage + (cell.totalBytes or 0)
- end
- end
- return totalStorage
- end
- local names = peripheral.getNames()
- for _, side in ipairs(names) do
- local type = peripheral.getType(side) -- Added `local` to prevent accidental global variable overwrite
- if type == "meBridge" then
- ME = peripheral.wrap(side)
- print('Connected to "meBridge" on the ' .. side .. "\n")
- -- Check if getAvailableItemStorage exists before calling
- if ME.getAvailableItemStorage then
- print("Total Storage: " .. formatNumberWithCommas(ME.getAvailableItemStorage()))
- else
- print("getAvailableItemStorage function not found.")
- end
- -- Get the item
- --getItemDetails("minecraft:cobblestone")
- local cellItemStorage = getCellItemStorage()
- local nonByteStorage = ME.getAvailableItemStorage() - cellItemStorage
- local nonByteToByte = nonByteStorage / 8
- local realStorage = cellItemStorage + nonByteToByte
- print("Actual Storage: " .. formatNumberWithCommas(round(realStorage)))
- print("Items Stored: " .. formatNumberWithCommas(ME.getTotalItemStorage()))
- break -- Exit after finding the ME Bridge
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment