Updated:
Empty an inventory
/clear @s
This removes everything, including held items, armor and the offhand. The ender chest is untouched. There is no undo.
Remove specific items (Java)
| Goal | Command |
|---|---|
| All dirt | /clear @s minecraft:dirt |
| Only 10 dirt | /clear @s minecraft:dirt 10 |
| Every kind of log | /clear @s #minecraft:logs |
| Everyone's cobblestone | /clear @a minecraft:cobblestone |
A # means an item tag, such as all wood types of logs.
Count without removing (Java)
/clear @s minecraft:diamond 0
A count of 0 removes nothing and reports how many the player has. Use it to check payment before taking it.
Only special items (Java 1.20.5+)
/give @p minecraft:emerald[custom_data={coin:1b}] 10
/clear @p minecraft:emerald[custom_data={coin:1b}] 5
The first line gives marked emeralds as map currency; the second removes five marked ones and ignores normal emeralds. On 1.20.4 and earlier write minecraft:emerald{coin:1b}.
A shop payment (Java)
execute as @p store result score @s coins run clear @s minecraft:emerald 0
execute as @p[scores={coins=5..}] run give @s minecraft:diamond 1
execute as @p[scores={coins=5..}] run clear @s minecraft:emerald 5
Create the score first with /scoreboard objectives add coins dummy. The first line stores the emerald count, and the next two give a diamond and take five emeralds only when the player has enough. Put the first in an impulse block behind a button and chain the other two.
Bedrock Edition
/clear @s dirt 0 10
Bedrock writes player, item, data value, count. Data value -1 matches every variant; leaving out the count removes all of that item.
Common problems
- "No items were found": the player does not have it, or the ID is wrong.
- @s does nothing in a command block: use @p or @a.
- Items on the ground: /clear only affects inventories; use /kill @e[type=minecraft:item].
- XP: not affected; use /xp.
Check your command
The Command Error Doctor checks common syntax mistakes in your browser.