Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the player whose chests we want to find
- local playerName = "playername"
- -- Initialize the Advanced Peripherals API
- local ap = peripheral.find("ap_util")
- -- Define a function to check if a block is a chest belonging to the player
- local function isChestForPlayer(block, player)
- -- Check if the block is a chest
- if block.getName() ~= "minecraft:chest" then
- return false
- end
- -- Check if the chest belongs to the specified player
- local chestOwner = ap.getChestOwner(block)
- if not chestOwner or chestOwner ~= player then
- return false
- end
- -- If the block is a chest belonging to the player, return true
- return true
- end
- -- Search for all chests in the loaded chunk
- local chests = ap.getBlocks("minecraft:chest")
- -- Filter the chests to only those belonging to the specified player
- local playerChests = {}
- for _, chest in ipairs(chests) do
- if isChestForPlayer(chest, playerName) then
- table.insert(playerChests, chest)
- end
- end
- -- Display the number of chests found, and their positions
- print("Found " .. #playerChests .. " chests belonging to " .. playerName)
- for _, chest in ipairs(playerChests) do
- print(" " .. chest.getPosition())
- end
Advertisement
Add Comment
Please, Sign In to add comment