/clear
Removes items from a player's inventory. Can target specific items and limit how many are removed.
Syntax
/clear [<targets>] [<item>] [<maxCount>]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| targets | entity | Optional | The player(s) whose inventory to clear. Defaults to the executing player. |
| item | item_predicate | Optional | The item to remove. If omitted, all items are cleared. |
| maxCount | integer | Optional | The maximum number of items to remove. If 0, counts matching items without removing them. |
Examples
/clear @pClears the entire inventory of the nearest player.
/clear @a minecraft:dirtRemoves all dirt blocks from every player's inventory.
/clear @s minecraft:diamond 0Checks how many diamonds the executing player has without removing any (useful in command blocks).
Common Mistakes
- Forgetting that maxCount 0 tests for the item but does not remove it, useful for detection but surprising if you expected deletion.
- Not specifying an item when you only want to remove a specific type, omitting the item argument clears the ENTIRE inventory.
Notes
When maxCount is 0 the command succeeds if the player has the item but removes nothing. This is useful for testing in conditional command blocks.
Related Commands
Need a Minecraft server?
Try these commands on Astroworld or host your own server.
Try Astroworld Hosting