Commands/clear

From Minecraft Wiki
Jump to: navigation, search
clear
Restrictions

Operator

First introduced

Java Edition 1.4.2 (12w37a)

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

Syntax[edit]

  • Java Edition
clear [<targets>] [<item>] [<maxCount>]
  • Bedrock Edition
clear [player: target] [itemName: Item] [data: int] [maxCount: int]

Arguments[edit]

JE<targets>: entity
BE: player: target: CommandSelector<Player>

Must be a player name, a target selector or a UUID[Java Edition only]. And the target selector must be of player type.
Specifies the player(s) whose items are cleared. If not specified, defaults to the player who executes the command.

JE<item>: item_predicate
BE: itemName: Item: CommandItem

In Java Edition, it must be a item argument (accepts item tags). In Bedrock Edition, it must be a item id or a block ID for which items exist.
Specifies the item to be cleared. If not specified, all items are cleared.

data: int: int

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

JE<maxCount>: integer
BE: maxCount: int: int

Must be a 32-bit integer number. In Java Edition, it must be between 0 and 2147483647 (inclusive). In Bedrock Edition, it must be between -1 and 2147483647 (inclusive).
Specifies the maximum number of items to be cleared. If not specified, or if -1[Bedrock Edition only], all items that match item, or itemName: Item and data: int are cleared. If 0, instead of clearing of items, detectes and queries the amount of specified items.

Result[edit]

CommandTriggerJava EditionBedrock Edition
anythe arguments are not specified correctly Unparseable Failed
if <targets> or player: target is not specified and the command executor is not a player. Failed
if <targets> or player: target fails to resolve to one or more online players
there are no specified items in any player's inventory.
On successRemoves or detects the specified items.

Output[edit]

CommandEditionSituationSuccess Count/execute store success .../execute store result ...
anyJava EditionOn fail000
On success11the number of total items that are cleared or detected.
Bedrock EditionOn fail0N/AN/A
On successthe number of players who have the specified items.N/AN/A

Note[edit]

Items in the the inventory and items from container (chest, crafting table, etc.) dragging over the cursor can be cleared.

In Bedrock Edition, items dragging from the inventory can also be cleared, while in Java Edition only if not in creative mode can these be cleared.

In Java Edition, items in players' four crafting slots can also be cleared.

In Bedrock Edition, if a player has more than one stack of item with specified ID and different data values (For example planks 0 and planks 1). When clearing with a specific data: int, The command first quiries how many specified items in the inventory can be cleared, then ignores data values and clears the corresponding amount of items with specified ID in the inventory from the left side of the hot bar to the right and from bottom to top.

Examples[edit]

  • To clear your entire inventory: clear
  • To clear all items from Alice's inventory: clear Alice
  • To clear all wool items from Alice's inventory: clear Alice minecraft:wool
  • To clear all orange wool items from the inventory of all players: clear @a minecraft:wool 1[Bedrock Edition only] or clear @a minecraft:orange_wool[Java Edition only]
  • To clear all golden swords with the "Sharpness I" enchantment from the nearest player
    • clear @p minecraft:golden_sword{Enchantments:[{id:"minecraft:sharpness",lvl:1s}]}[Java Edition only]
  • To test if a random player has stone in his inventory: clear @r minecraft:stone -1 0[Bedrock Edition only] or clear @r minecraft:stone 0[Java Edition only]

See also[edit]

  • /data — can change or remove items in block or entity inventories
  • /give — give items to player
  • /kill — can destroy item entities
  • /replaceitem — can replace items in block or entity inventories

History[edit]

Java Edition
1.4.212w37aAdded /clear.
12w38aAdded item argument to /clear.
1.814w02aAdded data argument to /clear.
1.915w31b/clear now clears the offhand slot.
1.1317w45aThe syntax of /clear has changed from /clear [<target>] [<item>] [<data>] [<count>] [<nbt>] to /clear [<target>] [<item>] [<count>].
Pocket Edition
1.0.5alpha 1.0.5.0Added /clear.