DorianH935

Untitled

Jul 20th, 2024 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. -- Find peripherals
  2. local vlt = peripheral.find("create:item_vault")
  3. local srn = peripheral.find("monitor")
  4.  
  5. -- Function to clear the monitor
  6. local function clearScreen()
  7. srn.clear()
  8. srn.setCursorPos(1, 1)
  9. end
  10.  
  11. -- Function to display a message on the monitor
  12. local function displayMessage(message, x, y)
  13. srn.setCursorPos(x, y)
  14. srn.write(message)
  15. end
  16.  
  17. -- Function to abbreviate numbers
  18. local function abbreviateNumber(num)
  19. if num >= 1e6 then
  20. return string.format("%.1fM", num / 1e6)
  21. elseif num >= 1e3 then
  22. return string.format("%.1fK", num / 1e3)
  23. else
  24. return tostring(num)
  25. end
  26. end
  27.  
  28. -- Initialize cursor position
  29. local cursorPos = 1
  30.  
  31. -- Main loop
  32. while true do
  33. clearScreen()
  34. local y = 1
  35.  
  36. -- Check if the vault is found
  37. if not vlt then
  38. displayMessage("Vault Not Found", 5, 4)
  39. else
  40. local itemList = vlt.list()
  41.  
  42. -- Check if the vault list is retrieved
  43. if not itemList then
  44. displayMessage("Searching For Vault...", 6, 4)
  45. else
  46. -- Create a table to hold the merged item counts
  47. local mergedItems = {}
  48.  
  49. -- Merge items by name
  50. for slot, item in pairs(itemList) do
  51. if mergedItems[item.name] then
  52. mergedItems[item.name] = mergedItems[item.name] + item.count
  53. else
  54. mergedItems[item.name] = item.count
  55. end
  56. end
  57.  
  58. -- Determine the number of items to display
  59. local numItems = 0
  60. for _ in pairs(mergedItems) do
  61. numItems = numItems + 1
  62. end
  63.  
  64. -- Display the merged items with abbreviated counts
  65. for itemName, itemCount in pairs(mergedItems) do
  66. if y == cursorPos then
  67. -- Display the cursor character
  68. displayMessage("> " .. abbreviateNumber(itemCount) .. "x " .. itemName, 1, y)
  69. else
  70. displayMessage(" " .. abbreviateNumber(itemCount) .. "x " .. itemName, 1, y)
  71. end
  72. y = y + 1
  73. end
  74.  
  75. -- Ensure cursor position is within bounds
  76. cursorPos = math.max(1, math.min(cursorPos, numItems))
  77.  
  78. -- Debugging line to show current cursor position
  79. print("Cursor Position: " .. cursorPos .. " / " .. numItems)
  80. end
  81. end
  82.  
  83. -- Read redstone signals from bundled cable
  84. local bundledInput = redstone.getBundledInput("top")
  85. print("Bundled Input: " .. bundledInput) -- Debugging line
  86.  
  87. -- Directly compare the bundledInput value
  88. if bundledInput == 2048 then
  89. if cursorPos < (numItems or 1) then
  90. cursorPos = cursorPos + 1 -- Move cursor down
  91. print("Moving cursor down to position: " .. cursorPos) -- Debugging line
  92. else
  93. print("Cursor is at the bottom; cannot move down") -- Debugging line
  94. end
  95. os.sleep(0.2) -- Debounce time
  96. elseif bundledInput == 16384 then
  97. if cursorPos > 1 then
  98. cursorPos = cursorPos - 1 -- Move cursor up
  99. print("Moving cursor up to position: " .. cursorPos) -- Debugging line
  100. else
  101. print("Cursor is at the top; cannot move up") -- Debugging line
  102. end
  103. os.sleep(0.2) -- Debounce time
  104. end
  105.  
  106. -- Wait for a redstone event before refreshing
  107. os.pullEvent("redstone")
  108. end
  109.  
Advertisement
Add Comment
Please, Sign In to add comment