Commands/clear

Clears items from player inventory, including items being dragged by the player.

Syntax

 * Java Edition


 * Bedrock Edition

Arguments
(BE: )
 * Must be a player name or a target selector. If not specified, defaults to the player who executed the command. Not optional if the executor isn't a player.
 * Entities other than players are not allowed.

(BE: )
 * Specifies the id of the item to be cleared. If not specified, all items in the player's inventory are cleared.


 * Specifies the data value of the item to be cleared. If not specified, or if, all items that match "itemName: Item" are cleared, regardless of their data. Must be an integer between -1 and 2,147,483,647 (inclusive, without the commas), but values that are invalid for the specified item id revert to 0.

(BE: )
 * Specifies the maximum number of items to be cleared. If not specified, or if, all items that match item and data are cleared. If  , does not clear items, but returns successfully if there were items that could have been cleared (allowing detection of items rather than clearing of items). Must be an integer less than 2,147,483,648.

Result
Fails if the arguments are not specified correctly, if  fails to resolve to one or more online players, or if no items are removed (except when  is  )

On success, removes the specified items from the player(s). If maxCount is 0, no items are removed, and the number of matching items are displayed in chat.

If a player has a two specified items with the same name but different [data: int] (For example light_block 1 7 and light_block 1 15) and the user clears their inventory of a specific [data: int], the command will always clear their inventory of the first item that is has the same [ItemName: Item] from the left side of the hot bar to the right, bottom to top of the inventory.

The specific outputs are as follows:

Examples

 * To clear your entire inventory:
 * To clear all items from Alice's inventory:
 * To clear all wool items from Alice's inventory:
 * To clear all orange wool items from the inventory of all players:  or
 * To clear all golden swords with the "Sharpness I" enchantment from the nearest player
 * To test if a random player has stone in his inventory:  or
 * To test if a random player has stone in his inventory:  or

History
Befehl/clear Comandos/clear Команды консоли/clear คำสั่ง/clear Команди консолі/clear 命令/clear