Loneranger419

totalMeDebug.lua

Feb 3rd, 2025 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. local function round(n)
  2. return math.floor(n + 0.5)
  3. end
  4.  
  5. local function formatNumberWithCommas(n)
  6. local formatted = tostring(n):reverse():gsub("(%d%d%d)", "%1,"):reverse()
  7. return formatted:match("^,") and formatted:sub(2) or formatted
  8. end
  9.  
  10. local function getItemDetails(itemName)
  11. local item = ME.getItem({ name = itemName }) -- Ensure correct item ID
  12.  
  13. if item then
  14. print("\n" .. item.displayName .. " details:") -- Print item display name
  15. for key, value in pairs(item) do
  16. print(key .. ": " .. tostring(value)) -- Print all key-value pairs
  17. end
  18. else
  19. print(itemName .. " not found in the system.")
  20. end
  21. end
  22.  
  23. local function getCellInfo()
  24. local cells = ME.listCells() -- Get storage cells
  25.  
  26. if not cells or #cells == 0 then
  27. print("No storage cells found.")
  28. return
  29. end
  30.  
  31. print("\nStorage Cells Info:")
  32. for index, cell in ipairs(cells) do
  33. print("\nCell #" .. index)
  34. for key, value in pairs(cell) do
  35. print(" " .. key .. ": " .. tostring(value))
  36. end
  37. end
  38. end
  39.  
  40. local function getCellItemStorage()
  41. local cells = ME.listCells() -- Get storage cells
  42.  
  43. if not cells or #cells == 0 then
  44. print("No storage cells found.")
  45. return 0 -- Return 0 if no cells exist
  46. end
  47.  
  48. local totalStorage = 0
  49.  
  50. for _, cell in ipairs(cells) do
  51. if cell.type == "item" then -- Only sum item storage cells
  52. totalStorage = totalStorage + (cell.totalBytes or 0)
  53. end
  54. end
  55.  
  56. return totalStorage
  57. end
  58.  
  59.  
  60. local names = peripheral.getNames()
  61.  
  62. for _, side in ipairs(names) do
  63. local type = peripheral.getType(side) -- Added `local` to prevent accidental global variable overwrite
  64.  
  65. if type == "meBridge" then
  66. ME = peripheral.wrap(side)
  67. print('Connected to "meBridge" on the ' .. side .. "\n")
  68.  
  69. -- Check if getAvailableItemStorage exists before calling
  70. if ME.getAvailableItemStorage then
  71. print("Total Storage: " .. formatNumberWithCommas(ME.getAvailableItemStorage()))
  72. else
  73. print("getAvailableItemStorage function not found.")
  74. end
  75.  
  76. -- Get the item
  77. --getItemDetails("minecraft:cobblestone")
  78.  
  79. local cellItemStorage = getCellItemStorage()
  80. local nonByteStorage = ME.getAvailableItemStorage() - cellItemStorage
  81. local nonByteToByte = nonByteStorage / 8
  82. local realStorage = cellItemStorage + nonByteToByte
  83. print("Actual Storage: " .. formatNumberWithCommas(round(realStorage)))
  84. print("Items Stored: " .. formatNumberWithCommas(ME.getTotalItemStorage()))
  85.  
  86. break -- Exit after finding the ME Bridge
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment