Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/clear: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Remove broken links to missing pages
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
 
Line 13: Line 13:
Items in the inventory and items from container (chest, crafting table, etc.) dragging over the cursor can be cleared.
Items in the inventory and items from container (chest, crafting table, etc.) dragging over the cursor can be cleared.


{{IN|bedrock}}, items dragging from the inventory can also be cleared, while {{in|java}} only if not in creative mode can these be cleared.
{{MC/In|bedrock}}, items dragging from the inventory can also be cleared, while {{MC/In|java}} only if not in creative mode can these be cleared.


{{IN|java}}, items in players' four crafting slots can also be cleared.
{{MC/In|java}}, items in players' four crafting slots can also be cleared.


== Syntax ==
== Syntax ==
Line 26: Line 26:


== Arguments ==
== Arguments ==
{{argument|targets|entity|player: target|CommandSelector<Player>}}
{{MC/Argument|targets|entity|player: target|CommandSelector<Player>}}
: Specifies the player(s) whose items are cleared. If not specified, defaults to the player who executes the command.
: Specifies the player(s) whose items are cleared. If not specified, defaults to the player who executes the command.
: {{arg desc|je=entity|amount=multiple|type=players|be=player}}
: {{MC/Arg desc|je=entity|amount=multiple|type=players|be=player}}


{{argument|item|item_predicate|itemName: Item|enum}}
{{MC/Argument|item|item_predicate|itemName: Item|enum}}
: Specifies the item to be cleared. If not specified, all items are cleared.
: Specifies the item to be cleared. If not specified, all items are cleared.
: {{arg desc|je=item_predicate|be=CommandItem}}
: {{MC/Arg desc|je=item_predicate|be=CommandItem}}


{{argument|be=1|data: int|int}}
{{MC/Argument|be=1|data: int|int}}
: Specifies the [[Minecraft:Bedrock Edition data values|data value]] of the item to be cleared. If not specified, or if <code>-1</code>, all items that match <code>itemName: Item</code> are cleared, regardless of their data. Values (bitwise AND 0xFFFF) that are invalid for the specified item id revert to 0.
: Specifies the [[Minecraft:Bedrock Edition data values|data value]] of the item to be cleared. If not specified, or if <code>-1</code>, all items that match <code>itemName: Item</code> are cleared, regardless of their data. Values (bitwise AND 0xFFFF) that are invalid for the specified item id revert to 0.
: {{arg desc|be=int}} Should be between -1 and 2,147,483,647 (inclusive, without commas).
: {{MC/Arg desc|be=int}} Should be between -1 and 2,147,483,647 (inclusive, without commas).


{{argument|maxCount|integer|maxCount: int|int}}
{{MC/Argument|maxCount|integer|maxCount: int|int}}
: Specifies the maximum number of items to be cleared. If not specified, or if <code>-1</code>{{only|bedrock}}, all items that match <code>item</code>, or <code>itemName: Item</code> and <code>data: int</code> are cleared. If <code>0</code>, instead of clearing of items, detects and queries the amount of specified items.
: Specifies the maximum number of items to be cleared. If not specified, or if <code>-1</code>{{only|bedrock}}, all items that match <code>item</code>, or <code>itemName: Item</code> and <code>data: int</code> are cleared. If <code>0</code>, instead of clearing of items, detects and queries the amount of specified items.
: {{arg desc|be=int|je=integer|min=0}} {{IN|bedrock}}, it should be between -1 and 2147483647 (inclusive).
: {{MC/Arg desc|be=int|je=integer|min=0}} {{MC/In|bedrock}}, it should be between -1 and 2147483647 (inclusive).


== Result ==
== Result ==
Line 57: Line 57:
== Output ==
== Output ==


{{Output table}}
{{MC/Output table}}
{{Output table|edition=je|On fail|0|0|0}}
{{MC/Output table|edition=je|On fail|0|0|0}}
{{Output table|On success|1|1|the number of total items that are cleared or detected.}}
{{MC/Output table|On success|1|1|the number of total items that are cleared or detected.}}
{{Output table|edition=be|On fail|0}}
{{MC/Output table|edition=be|On fail|0}}
{{Output table|On success|the number of players who have the specified items.}}
{{MC/Output table|On success|the number of players who have the specified items.}}
{{Output table}}
{{MC/Output table}}


== Examples ==
== Examples ==
Line 76: Line 76:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.4.2|dev=12w37a|Added {{cmd|clear|link=none}}.}}
|{{HistoryLine||1.4.2|dev=12w37a|Added {{MC/Cmd|clear|link=none}}.}}
|{{HistoryLine|||dev=12w38a|Added {{cd|item}} argument to {{cmd|clear|link=none}}.}}
|{{HistoryLine|||dev=12w38a|Added {{MC/Cd|item}} argument to {{MC/Cmd|clear|link=none}}.}}
|{{HistoryLine||1.8|dev=14w02a|Added {{cd|data}} argument to {{cmd|clear|link=none}}.}}
|{{HistoryLine||1.8|dev=14w02a|Added {{MC/Cd|data}} argument to {{MC/Cmd|clear|link=none}}.}}
|{{HistoryLine||1.9|dev=15w31b|{{cmd|clear|link=none}} now clears the offhand slot.}}
|{{HistoryLine||1.9|dev=15w31b|{{MC/Cmd|clear|link=none}} now clears the offhand slot.}}
|{{HistoryLine||1.13|dev=17w45a|The syntax of {{cmd|clear|link=none}} has changed from {{cmd|clear [<target>] [<item>] [<data>] [<count>] [<nbt>]}} to
|{{HistoryLine||1.13|dev=17w45a|The syntax of {{MC/Cmd|clear|link=none}} has changed from {{MC/Cmd|clear [<target>] [<item>] [<data>] [<count>] [<nbt>]}} to
  {{cmd|clear [<target>] [<item>] [<count>]}}.}}
  {{MC/Cmd|clear [<target>] [<item>] [<count>]}}.}}
|{{HistoryLine||1.16|dev=20w07a|{{cmd|clear|link=none}} now clears the items in the inventory crafting grid.}}
|{{HistoryLine||1.16|dev=20w07a|{{MC/Cmd|clear|link=none}} now clears the items in the inventory crafting grid.}}
|{{HistoryLine|||dev=20w22a|{{cmd|clear|link=none}} now works properly with the inventory crafting grid.}}
|{{HistoryLine|||dev=20w22a|{{MC/Cmd|clear|link=none}} now works properly with the inventory crafting grid.}}
|{{HistoryLine||1.20.5|dev=24w09a|Updated the syntax. Now uses item components instead of NBT tags.|Now target items must have every component that is the same as the specified key-value pair, or the default value of the component if it is not specified.}}
|{{MC/HistoryLine||1.20.5|dev=24w09a|Updated the syntax. Now uses item components instead of NBT tags.|Now target items must have every component that is the same as the specified key-value pair, or the default value of the component if it is not specified.}}
}}
}}


=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|pocket}}
|{{MC/HistoryLine|pocket}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{cmd|clear|link=none}}.}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{MC/Cmd|clear|link=none}}.}}
}}
}}


== See also ==
== See also ==
* {{cmd|data}} — can change or remove items in block or entity inventories
* {{MC/Cmd|data}} — can change or remove items in block or entity inventories
* {{cmd|give}} — give items to player
* {{MC/Cmd|give}} — give items to player
* {{cmd|kill}} — can destroy item entities
* {{MC/Cmd|kill}} — can destroy item entities
* {{cmd|item}}{{only|java}} — can manipulate items in block or entity inventories
* {{MC/Cmd|item}}{{only|java}} — can manipulate items in block or entity inventories
* {{cmd|replaceitem}}{{only|bedrock}} — can replace items in block or entity inventories
* {{MC/Cmd|replaceitem}}{{only|bedrock}} — can replace items in block or entity inventories


== External links ==
== External links ==
Line 106: Line 106:


== Navigation ==
== Navigation ==
{{Navbox commands}}
{{MC/Navbox commands}}


de:Befehl/clear
de:Befehl/clear

Latest revision as of 20:08, 9 April 2026

Template:Infobox command

Clears Minecraft:items from player Minecraft:inventory, including items being dragged by the player. Can also detect and query the amount of specified items.

Usage

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

in Template:Editions, items dragging from the inventory can also be cleared, while in Template:Editions only if not in creative mode can these be cleared.

in Template:Editions, items in players' four crafting slots can also be cleared.

Syntax

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

Arguments

Template:El<targets>: entity
Template:El: player: target: CommandSelector<Player>

Specifies the player(s) whose items are cleared. If not specified, defaults to the player who executes the command.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

Template:El<item>: item_predicate
Template:El: itemName: Item: enum

Specifies the item to be cleared. If not specified, all items are cleared.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|item_predicate}}{{#vardefine:be-arg|item_be}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}

data: int: int

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 (bitwise AND 0xFFFF) that are invalid for the specified item id revert to 0.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|integer}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} Should be between -1 and 2,147,483,647 (inclusive, without commas).

Template:El<maxCount>: integer
Template:El: maxCount: int: int

Specifies the maximum number of items to be cleared. If not specified, or if -1Template:Only, all items that match item, or itemName: Item and data: int are cleared. If 0, instead of clearing of items, detects and queries the amount of specified items.
{{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|integer}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} in Template:Editions, it should be between -1 and 2147483647 (inclusive).

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|the number of total items that are cleared or detected.}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|be}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|the number of players who have the specified items.}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}

{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}

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:woolTemplate:Only
  • To clear all orange wool items from the inventory of all players: clear @a minecraft:wool 1Template:Only or clear @a minecraft:orange_wool
  • 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}]}Template:Only
  • To test if a random player has stone in their inventory: clear @r minecraft:stone 0 0Template:Only or clear @r minecraft:stone 0Template:Only

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

See also

  1. REDIRECT Template:Command

Template:Redr — can change or remove items in block or entity inventories

  1. REDIRECT Template:Command

Template:Redr — give items to player

  1. REDIRECT Template:Command

Template:Redr — can destroy item entities

  1. REDIRECT Template:Command

Template:RedrTemplate:Only — can manipulate items in block or entity inventories

  1. REDIRECT Template:Command

Template:RedrTemplate:Only — can replace items in block or entity inventories

External links

Navigation

All editions
Removed
Template:El only
Debug
Removed
Template:Els only
Template:El only
Removed
Template:El only
Removed
Template:Els only
Removed
Joke
Related

de:Befehl/clear es:Comandos/clear fr:Commandes/clear ja:コマンド/clear ko:명령어/clear pt:Comandos/clear ru:Команды консоли/clear th:คำสั่ง/clear uk:Команди консолі/clear zh:命令/clear