Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Find peripherals
- local vlt = peripheral.find("create:item_vault")
- local srn = peripheral.find("monitor")
- -- Function to clear the monitor
- local function clearScreen()
- srn.clear()
- srn.setCursorPos(1, 1)
- end
- -- Function to display a message on the monitor
- local function displayMessage(message, x, y)
- srn.setCursorPos(x, y)
- srn.write(message)
- end
- -- Function to abbreviate numbers
- local function abbreviateNumber(num)
- if num >= 1e6 then
- return string.format("%.1fM", num / 1e6)
- elseif num >= 1e3 then
- return string.format("%.1fK", num / 1e3)
- else
- return tostring(num)
- end
- end
- -- Initialize cursor position
- local cursorPos = 1
- -- Main loop
- while true do
- clearScreen()
- local y = 1
- -- Check if the vault is found
- if not vlt then
- displayMessage("Vault Not Found", 5, 4)
- else
- local itemList = vlt.list()
- -- Check if the vault list is retrieved
- if not itemList then
- displayMessage("Searching For Vault...", 6, 4)
- else
- -- Create a table to hold the merged item counts
- local mergedItems = {}
- -- Merge items by name
- for slot, item in pairs(itemList) do
- if mergedItems[item.name] then
- mergedItems[item.name] = mergedItems[item.name] + item.count
- else
- mergedItems[item.name] = item.count
- end
- end
- -- Determine the number of items to display
- local numItems = 0
- for _ in pairs(mergedItems) do
- numItems = numItems + 1
- end
- -- Display the merged items with abbreviated counts
- for itemName, itemCount in pairs(mergedItems) do
- if y == cursorPos then
- -- Display the cursor character
- displayMessage("> " .. abbreviateNumber(itemCount) .. "x " .. itemName, 1, y)
- else
- displayMessage(" " .. abbreviateNumber(itemCount) .. "x " .. itemName, 1, y)
- end
- y = y + 1
- end
- -- Ensure cursor position is within bounds
- cursorPos = math.max(1, math.min(cursorPos, numItems))
- -- Debugging line to show current cursor position
- print("Cursor Position: " .. cursorPos .. " / " .. numItems)
- end
- end
- -- Read redstone signals from bundled cable
- local bundledInput = redstone.getBundledInput("top")
- print("Bundled Input: " .. bundledInput) -- Debugging line
- -- Directly compare the bundledInput value
- if bundledInput == 2048 then
- if cursorPos < (numItems or 1) then
- cursorPos = cursorPos + 1 -- Move cursor down
- print("Moving cursor down to position: " .. cursorPos) -- Debugging line
- else
- print("Cursor is at the bottom; cannot move down") -- Debugging line
- end
- os.sleep(0.2) -- Debounce time
- elseif bundledInput == 16384 then
- if cursorPos > 1 then
- cursorPos = cursorPos - 1 -- Move cursor up
- print("Moving cursor up to position: " .. cursorPos) -- Debugging line
- else
- print("Cursor is at the top; cannot move up") -- Debugging line
- end
- os.sleep(0.2) -- Debounce time
- end
- -- Wait for a redstone event before refreshing
- os.pullEvent("redstone")
- end
Advertisement
Add Comment
Please, Sign In to add comment