Commands/clear

From Minecraft Wiki
Jump to: navigation, search
clear
Restrictions

Operator

First introduced

Java Edition 1.4.2 (12w37a)
PE 1.0.5 (Pocket Edition alpha 1.0.5.0)

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]

<targets> (BE: player: target)

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.

<item> (BE: itemName: Item)

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

data: int[Bedrock Edition only]

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. 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.

<maxCount> (BE: maxCount: int)

Specifies the maximum number of items to be cleared. If not specified, or if -1[Bedrock Edition only], all items that match item and data are cleared. If 0, 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[edit]

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

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. ‌[Bedrock Edition only]



The specific outputs are as follows:

Trigger Type Message
Item does not exist Failure Unknown item <item id>
/clear <selector> <item id><--[HERE]
Item tag does not exist Failure Unknown item tag <tag id>

The player has an empty inventory
The player does not have the specified items

Failure

Single player: No items were found on player <player name>
Multiple players: No items were found on <number> players[verify]

The selector targets non-player entities Failure Only players may be affected by this command, but the provided selector includes entities
No players are affected given the selector Failure No player was found
Items are removed from the inventory Success

Single player: Removed <number> items from player <player name>
Multiple players: Removed <number> items from <number> players[verify]

The maxCount is set to 0 and the player has the specified items in their inventory Success

Single player: Found <number> matching items on player <player name>
Multiple players: Found <number> matching items on <number> players[verify]

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]

This section is a stub, meaning that it lacks some important information. You can help by expanding it with further information relating to the topic.
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.