dcchill

Untitled

Apr 21st, 2023
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. -- Define the player whose chests we want to find
  2. local playerName = "playername"
  3.  
  4. -- Initialize the Advanced Peripherals API
  5. local ap = peripheral.find("ap_util")
  6.  
  7. -- Define a function to check if a block is a chest belonging to the player
  8. local function isChestForPlayer(block, player)
  9. -- Check if the block is a chest
  10. if block.getName() ~= "minecraft:chest" then
  11. return false
  12. end
  13.  
  14. -- Check if the chest belongs to the specified player
  15. local chestOwner = ap.getChestOwner(block)
  16. if not chestOwner or chestOwner ~= player then
  17. return false
  18. end
  19.  
  20. -- If the block is a chest belonging to the player, return true
  21. return true
  22. end
  23.  
  24. -- Search for all chests in the loaded chunk
  25. local chests = ap.getBlocks("minecraft:chest")
  26.  
  27. -- Filter the chests to only those belonging to the specified player
  28. local playerChests = {}
  29. for _, chest in ipairs(chests) do
  30. if isChestForPlayer(chest, playerName) then
  31. table.insert(playerChests, chest)
  32. end
  33. end
  34.  
  35. -- Display the number of chests found, and their positions
  36. print("Found " .. #playerChests .. " chests belonging to " .. playerName)
  37. for _, chest in ipairs(playerChests) do
  38. print(" " .. chest.getPosition())
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment