Updated:
1. Read the inventory (Java)
/data get entity Steve Inventory
/data get entity Steve equipment
Since 1.21.5, armor and the offhand are stored in equipment, not Inventory. See the data command.
2. Ender chest contents (Java)
/data get entity Steve EnderItems
3. Count one item (Java)
/clear Steve diamond 0
A max count of 0 only reports how many were found. Forget the 0 and every diamond is removed.
4. Select players holding an item
/execute as @a if items entity @s container.* minecraft:diamond run say I have diamonds
Java 1.20.5+. Use weapon.mainhand to check only the held item. On Bedrock use hasitem:
/tag @a[hasitem={item=diamond}] add has_diamond
5. Take items away
/clear Steve diamond
See the clear command.
6. Rank everyone by item count (Java)
/scoreboard objectives add dia dummy "Diamonds"
/execute as @a store result score @s dia run clear @s diamond 0
/scoreboard objectives setdisplay sidebar dia
Counts each player's diamonds into a sidebar score without removing them.
7. Check for a special item such as a ticket (Java)
/give @s minecraft:paper[custom_data={ticket:1b},custom_name={"text":"Entry Ticket","italic":false}]
/execute as @a if items entity @s container.* minecraft:paper[custom_data~{ticket:1b}] run tag @s add has_ticket
The first line hands out paper with a hidden custom_data marker. The second tags players carrying it, and plain paper does not count, so nobody can craft a fake. The name uses the 1.21.5+ form. See the villager shop for trading tickets.
Troubleshooting
- Player not found: offline players cannot be inspected.
- Output too long: read one slot with
Inventory[0]. - Bedrock has no /data: use hasitem checks instead.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.