Commands/clear

From Minecraft Wiki
Jump to: navigation, search
clear
Restrictions

Operator

First introduced

1.4.2 (12w37a)
PE 1.0.5 (PE 1.0.5 build 1)

Clears items from player inventory.

Syntax
  • Java Edition
clear [player] [item] [data] [maxCount] [dataTag]
clear [<targets>] [<item>] [<count>][upcoming 1.13]
  • Pocket Edition
clear [player: target] [itemName: string] [data: int] [maxCount: int]
Arguments
player (PE: player: target or targets[upcoming 1.13]) (optional)
Must be a player name or a target selector. If not specified, defaults to the player who executed the command. Not optional in command blocks.
item (PE: itemName: string) (optional)
Specifies the id of the item to be cleared. If not specified, all items in the player's inventory are cleared.
data[until 1.13] (PE: data: int) (optional)
Specifies the data value of the item to be cleared. If not specified, or if -1, all items that match item are cleared, regardless of their data.
maxCount (count[upcoming 1.13]) (PE: maxCount: int) (optional)
Specifies the maximum number of items to be cleared. If not specified, or if -1, 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).
dataTag[until 1.13] (optional)[Java Edition only]
Specifies the data tags of the item to be cleared (only items matching the specified data tags will be cleared — data tags not specified will not be considered). Must be a compound NBT tag (for example, {display:{Name:Fred}}).
Result
Fails if the arguments are not specified correctly, if player 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).
Examples
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
To clear all golden swords with the "Sharpness I" enchantment from the nearest player, regardless of their damage value:
clear @p minecraft:golden_sword -1 -1 {ench:[{id:16s,lvl:1s}]} or clear @p minecraft:golden_sword{ench:[{id:16s,lvl:1s}]}[upcoming 1.13]
See also
/blockdata — can change or remove items in block inventories
/entitydata — can change or remove items in entity inventories
/give — give items to player
/kill — can destroy item entities
/replaceitem — can replace items in block or entity inventories