
Command
/clear
Removes items from players' inventories, or counts how many matching items they carry.
| /clear [<targets> [<item> [<maxCount>]]] |
| Argument | Kind of value | What to type |
|---|---|---|
| <targets> | Target selector | The players whose inventories are cleared. Defaults to yourself. One or more players. |
| <item> | Item test | Which items to remove: an item id such as minecraft:diamond, an item tag such as #minecraft:logs, or * for any item, optionally followed by component tests in square brackets. Defaults to every item. |
| <maxCount> | Whole number | The largest number of items to remove from each player. A whole number of 0 or more. 0 only counts. Without it, all matching items are removed. At least 0. |
| Permission level | 2: operators, worlds with cheats on, command blocks and functions |
| Works in | Singleplayer with cheats enabled and multiplayer servers. Needs permission level 2 (gamemasters): server operators, players with cheats, command blocks, and functions can all run it. |
| Result | Reports how many items were removed and from whom, or how many matching items were found when only counting. The number /execute store saves is that number of items, added up over all targeted players. |
| No arguments | Removes everything from your own inventory. This form only works when a player runs it. |
| Only targets | Removes every item from the targeted players. |
| What is searched | The whole inventory including armor and off hand, the 2x2 crafting grid, and the item held on the mouse cursor. |
| Counting only | A maxCount of 0 removes nothing and just reports how many matching items the players have. This is a way to test whether a player carries an item. |
| Failure | Fails with "No items were found" if no targeted player had a matching item. |
/clearEmpties your own inventory.
/clear @a minecraft:diamondRemoves all Diamonds from every player.
/clear @s minecraft:dirt 32Removes up to 32 Dirt from you.
/clear @p #minecraft:logsRemoves every kind of log from the nearest player.
/clear @s minecraft:diamond 0Counts your Diamonds without removing any.

