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

Minecraft:Target selectors: Difference between revisions

From SAS Gaming Wiki
imported>NRPAN1
 
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{distinguish|Target}}
{{MC/Distinguish|Target}}
'''Target selectors''' are used in [[Minecraft:commands]] to select players and entities arbitrarily, without needing to specify an exact player name or a [[Minecraft:Universally_unique_identifier|UUID]]. One or more entities can be selected with a target selector variable, and targets can be filtered from the selection based on certain criteria using the target selector arguments.
'''Target selectors''' are used in [[Minecraft:commands]] to select players and entities arbitrarily, without needing to specify an exact player name or a UUID. One or more entities can be selected with a target selector variable, and targets can be filtered from the selection based on certain criteria using the target selector arguments.


{{TOC limit}}
{{TOC limit}}
Line 26: Line 26:
| <code>@v</code> || all agents{{only|education|short=1}}
| <code>@v</code> || all agents{{only|education|short=1}}
|-
|-
| <code>@initiator</code> || the player who clicks an [[Minecraft:NPC]] [[Minecraft:dialogue]] button{{only|bedrock|education|short=1}}
| <code>@initiator</code> || the player who clicks an [[Minecraft:NPC]] dialogue button{{only|bedrock|education|short=1}}
|}
|}


A target selector variable identifies the broad category of targets to select. There are six in [[Minecraft:Java Edition|''Java Edition'']], seven in [[Minecraft:Bedrock Edition|''Bedrock Edition'']] and nine {{in|edu}}:
A target selector variable identifies the broad category of targets to select. There are six in [[Minecraft:Java Edition|''Java Edition'']], seven in [[Minecraft:Bedrock Edition|''Bedrock Edition'']] and nine {{MC/In|edu}}:


; <code>@p</code>
; <code>@p</code>
Line 35: Line 35:
: Selects the nearest player from the command's execution. If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected.
: Selects the nearest player from the command's execution. If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected.


: {{IN|Bedrock}}, <code>@p</code> selects only players who are alive.
: {{MC/In|Bedrock}}, <code>@p</code> selects only players who are alive.


; <code>@n</code>
; <code>@n</code>
Line 45: Line 45:
: Selects a random online player.
: Selects a random online player.


: In {{el|Bedrock}}, you can use <code>@r</code> to select non-player entities via the <code>type</code> selector argument; {{in|java}}, to select a random entity, use <code>@e[sort=random,limit=1]</code> or <code>@n[sort=random]</code> instead.
: In {{MC/El|Bedrock}}, you can use <code>@r</code> to select non-player entities via the <code>type</code> selector argument; {{MC/In|java}}, to select a random entity, use <code>@e[sort=random,limit=1]</code> or <code>@n[sort=random]</code> instead.
: {{IN|Bedrock}}, <code>@r</code> can select only entities who are alive.
: {{MC/In|Bedrock}}, <code>@r</code> can select only entities who are alive.


; <code>@a</code>
; <code>@a</code>
Line 70: Line 70:
; <code>@initiator</code>{{only|bedrock|education|short=1}}
; <code>@initiator</code>{{only|bedrock|education|short=1}}


: Selects the player who interacts with a button in a JSON [[Minecraft:NPC]] [[Minecraft:dialogue]].
: Selects the player who interacts with a button in a JSON [[Minecraft:NPC]] dialogue.


== Target selector arguments ==
== Target selector arguments ==
Line 167: Line 167:
: <code>@<variable>[<argument>=<value>,<argument>=<value>,...]</code>.
: <code>@<variable>[<argument>=<value>,<argument>=<value>,...]</code>.


{{IN|java}}, arguments and values are case-sensitive. Spaces are allowed around the brackets, equal signs, and commas, except {{in|java}} between the target variable and the first bracket. Commas must be used to separate argument-value pairs.
{{MC/In|java}}, arguments and values are case-sensitive. Spaces are allowed around the brackets, equal signs, and commas, except {{MC/In|java}} between the target variable and the first bracket. Commas must be used to separate argument-value pairs.


If there are multiple argument-value pairs, they all must be satisfied to add a potential target to the group. (In other words, they are AND-ed together).
If there are multiple argument-value pairs, they all must be satisfied to add a potential target to the group. (In other words, they are AND-ed together).


{{anchor|Selecting targets by coordinate}}
{{MC/Anchor|Selecting targets by coordinate}}
===Position arguments===
===Position arguments===


: <code>[x=<value>,y=<value>,z=<value>]</code> — Define a position in the world that the selector starts at, for use with the [[#Selecting targets by distance|distance]] argument, the [[#Selecting targets by volume|volume]] arguments, or the [[#Selecting targets with a limit|sort and limit]] arguments. Using these arguments alone does not restrict the entities found (except {{in|java}}), and affect only the sorting of targets. Cannot duplicate any one of these three arguments.
: <code>[x=<value>,y=<value>,z=<value>]</code> — Define a position in the world that the selector starts at, for use with the [[#Selecting targets by distance|distance]] argument, the [[#Selecting targets by volume|volume]] arguments, or the [[#Selecting targets with a limit|sort and limit]] arguments. Using these arguments alone does not restrict the entities found (except {{MC/In|java}}), and affect only the sorting of targets. Cannot duplicate any one of these three arguments.
: The positional components are doubles, allowing for values like <code>12.34</code>. {{IN|java}} they are not center-corrected, meaning <code>x=0</code> is not corrected to <code>x=0.5</code>. {{IN|bedrock}}, if distance or volume arguments are not used, positions that are written as integers ''are'' center-corrected,  <code>x=0</code> becomes <code>x=0.5</code>. To avoid this, use <code>x=0.0</code> instead.
: The positional components are doubles, allowing for values like <code>12.34</code>. {{MC/In|java}} they are not center-corrected, meaning <code>x=0</code> is not corrected to <code>x=0.5</code>. {{MC/In|bedrock}}, if distance or volume arguments are not used, positions that are written as integers ''are'' center-corrected,  <code>x=0</code> becomes <code>x=0.5</code>. To avoid this, use <code>x=0.0</code> instead.


: {{IN|bedrock}}, [[Minecraft:Coordinates#Relative world coordinates|tilde notation]] is available for selector argument coordinates. Note: [[Minecraft:Coordinates#Local coordinates|Caret notation]] is not.
: {{MC/In|bedrock}}, [[Minecraft:Coordinates#Relative world coordinates|tilde notation]] is available for selector argument coordinates. Note: [[Minecraft:Coordinates#Local coordinates|Caret notation]] is not.


: {{IN|java}}, these arguments limit the search of entities to the current dimension. For example <code>/execute in overworld as @e[x=0]</code> will select only entities that are in the ''overworld''.
: {{MC/In|java}}, these arguments limit the search of entities to the current dimension. For example <code>/execute in overworld as @e[x=0]</code> will select only entities that are in the ''overworld''.


===Selecting targets by distance===
===Selecting targets by distance===
Line 185: Line 185:
: Filter target selection based on their Euclidean distances from some point, searching for the target's feet (a point at the bottom of the center of their hitbox). If the positional arguments are left undefined, radius is calculated relative to the position of the command's execution. This argument limits the search of entities to the current dimension. Cannot duplicate these arguments.
: Filter target selection based on their Euclidean distances from some point, searching for the target's feet (a point at the bottom of the center of their hitbox). If the positional arguments are left undefined, radius is calculated relative to the position of the command's execution. This argument limits the search of entities to the current dimension. Cannot duplicate these arguments.


: {{IN|java}}: <code>[distance=<value>]</code> — Specifies the range of distance. [[Minecraft:Argument_types#minecraft:float_range|Float ranges]] are supported to select a specific region. Only unsigned values are allowed.
: {{MC/In|java}}: <code>[distance=<value>]</code> — Specifies the range of distance. Float ranges are supported to select a specific region. Only unsigned values are allowed.


: {{IN|bedrock}}: <code>[r=<value>]</code> and <code>[rm=<value>]</code> — Specifies the maximum and minimum range to find entities, respectively. Only unsigned values are allowed.
: {{MC/In|bedrock}}: <code>[r=<value>]</code> and <code>[rm=<value>]</code> — Specifies the maximum and minimum range to find entities, respectively. Only unsigned values are allowed.


: Examples {{in|Java}}:
: Examples {{MC/In|Java}}:
:* <code>@e[distance=10..]</code> — Target all entities more than ten blocks away.
:* <code>@e[distance=10..]</code> — Target all entities more than ten blocks away.
:* <code>@e[distance=..10]</code> — Target all entities less than ten blocks away.
:* <code>@e[distance=..10]</code> — Target all entities less than ten blocks away.
Line 195: Line 195:
:* <code>@e[distance=8..16]</code> — Target all entities more than eight blocks, but less than 16 blocks away (inclusive).
:* <code>@e[distance=8..16]</code> — Target all entities more than eight blocks, but less than 16 blocks away (inclusive).


: Examples {{in|Bedrock}}:
: Examples {{MC/In|Bedrock}}:
:* <code>@e[r=10]</code> — Target all entities that are ten or fewer blocks away.
:* <code>@e[r=10]</code> — Target all entities that are ten or fewer blocks away.
:* <code>@e[rm=10]</code> — Target all entities that are ten or more blocks away.
:* <code>@e[rm=10]</code> — Target all entities that are ten or more blocks away.
Line 205: Line 205:
: <code>[dx=<value>,dy=<value>,dz=<value>]</code> — Filter target selection based on their x-difference, y-difference, and z-difference from some point, as measured by entities' hitboxes. Cannot duplicate any one of these three arguments.
: <code>[dx=<value>,dy=<value>,dz=<value>]</code> — Filter target selection based on their x-difference, y-difference, and z-difference from some point, as measured by entities' hitboxes. Cannot duplicate any one of these three arguments.


: Numerically, this can be interpreted as creating a cuboid volume from the initial position {{code|(x,y,z)}} to {{code|(x+dx,y+dy,z+dz)}} but with the vector {{code|(1,1,1)}} added to the x-most, y-most, z-most corner (the upper south-east corner). Because of this, the volume to check can never be smaller than a cube with a side length of 1, and no single dimension of the volume can be less than 1. Then, all entities whose hitboxes at least partially intersect with that volume are selected. If the positional arguments are left out, the selection is interpreted as originating from the position of the command's execution. Any values are allowed, including signed and fractional numbers.
: Numerically, this can be interpreted as creating a cuboid volume from the initial position {{MC/Code|(x,y,z)}} to {{MC/Code|(x+dx,y+dy,z+dz)}} but with the vector {{MC/Code|(1,1,1)}} added to the x-most, y-most, z-most corner (the upper south-east corner). Because of this, the volume to check can never be smaller than a cube with a side length of 1, and no single dimension of the volume can be less than 1. Then, all entities whose hitboxes at least partially intersect with that volume are selected. If the positional arguments are left out, the selection is interpreted as originating from the position of the command's execution. Any values are allowed, including signed and fractional numbers.


: If all of the values are whole numbers, this can be interpreted as creating a volume of blocks from the initial position ({{code|x y z}}) to the delta position ({{code|x+dx y+dy z+dz)}}) and selecting any entity whose hitbox intersects with those blocks. So, if you have built a cuboid of blocks in the world, you can subtract the coordinates of one corner block from the coordinates of the opposite corner block to get the {{code|dx}}, {{code|dy}}, and {{code|dz}} values for selecting those entities.
: If all of the values are whole numbers, this can be interpreted as creating a volume of blocks from the initial position ({{MC/Code|x y z}}) to the delta position ({{MC/Code|x+dx y+dy z+dz)}}) and selecting any entity whose hitbox intersects with those blocks. So, if you have built a cuboid of blocks in the world, you can subtract the coordinates of one corner block from the coordinates of the opposite corner block to get the {{MC/Code|dx}}, {{MC/Code|dy}}, and {{MC/Code|dz}} values for selecting those entities.


: Note that {{code|dx}}, {{code|dy}}, and {{code|dz}} specify ''signed differences'' from the given coordinate. They do not specify a separate coordinate, nor do they extend in both the positive and negative directions as you might expect from a position predicate.
: Note that {{MC/Code|dx}}, {{MC/Code|dy}}, and {{MC/Code|dz}} specify ''signed differences'' from the given coordinate. They do not specify a separate coordinate, nor do they extend in both the positive and negative directions as you might expect from a position predicate.


: Additionally, when only one or two volume arguments are present, any that are not specified are assumed to be set to zero. For example, <code>@a[dx=15]</code> is equivalent to <code>@a[dx=15,dy=0,dz=0]</code>.
: Additionally, when only one or two volume arguments are present, any that are not specified are assumed to be set to zero. For example, <code>@a[dx=15]</code> is equivalent to <code>@a[dx=15,dy=0,dz=0]</code>.


: Examples:
: Examples:
:* <code>@e[x=1,y=2,z=3,dx=0,dy=0,dz=0]</code> — Select all entities whose hitbox intersects with the block at {{code|1 2 3}}.
:* <code>@e[x=1,y=2,z=3,dx=0,dy=0,dz=0]</code> — Select all entities whose hitbox intersects with the block at {{MC/Code|1 2 3}}.
:* <code>@e[x=1,y=2,z=3,dx=4,dy=5,dz=-6]</code> — Select all entities whose hitbox intersects with the block region {{code|1~5, 2~7, -3~3}}.
:* <code>@e[x=1,y=2,z=3,dx=4,dy=5,dz=-6]</code> — Select all entities whose hitbox intersects with the block region {{MC/Code|1~5, 2~7, -3~3}}.
:** (or, the numerically speaking, a cuboid from {{code|1.0 2.0 -3.0}} to {{code|6.0 8.0 4.0}}).
:** (or, the numerically speaking, a cuboid from {{MC/Code|1.0 2.0 -3.0}} to {{MC/Code|6.0 8.0 4.0}}).
:** (or, mathematically speaking, the region that is <code>{ (x,y,z)∈R³ | x∈[1.0,6.0], y∈[2.0,8.0], z∈[-3.0,4.0] }</code>), or <math>[1, 6] \times [2, 8] \times [-3, 4] \subset \mathbb R^3</math>
:** (or, mathematically speaking, the region that is <code>{ (x,y,z)∈R³ | x∈[1.0,6.0], y∈[2.0,8.0], z∈[-3.0,4.0] }</code>), or <math>[1, 6] \times [2, 8] \times [-3, 4] \subset \mathbb R^3</math>


Line 223: Line 223:
===Selecting targets by scores===
===Selecting targets by scores===


: <code>[scores={<objective>=<value>,...}]</code> — Filter target selection based on their scores in the specified objectives. All tested objectives are in a single object, separated by commas. Each objective and score value pair is separated by an equals sign. The score values support [[Minecraft:Argument_types#minecraft:int_range|integer ranges]]. Cannot duplicate this argument.
: <code>[scores={<objective>=<value>,...}]</code> — Filter target selection based on their scores in the specified objectives. All tested objectives are in a single object, separated by commas. Each objective and score value pair is separated by an equals sign. The score values support integer ranges. Cannot duplicate this argument.
:* <code>@e[scores={myscore=10}]</code> — Select all entities with a score in objective ''myscore'' of exactly ten.
:* <code>@e[scores={myscore=10}]</code> — Select all entities with a score in objective ''myscore'' of exactly ten.
:* <code>@e[scores={myscore=10..12}]</code> — Select all entities with a score in objective ''myscore'' of between ten and 12 (inclusive).
:* <code>@e[scores={myscore=10..12}]</code> — Select all entities with a score in objective ''myscore'' of between ten and 12 (inclusive).
Line 230: Line 230:
:* <code>@e[scores={foo=10,bar=1..5}]</code> — Select all entities with a score in objective ''foo'' of exactly ten, and a score in objective ''bar'' of between one and five (inclusive).
:* <code>@e[scores={foo=10,bar=1..5}]</code> — Select all entities with a score in objective ''foo'' of exactly ten, and a score in objective ''bar'' of between one and five (inclusive).


: {{IN|bedrock}}, <code>!</code> can be used to invert selection.
: {{MC/In|bedrock}}, <code>!</code> can be used to invert selection.
:*<code>@e[scores={myscore=!10}]</code> — Exclude any entities with a score in objective ''myscore'' of exactly ten.
:*<code>@e[scores={myscore=!10}]</code> — Exclude any entities with a score in objective ''myscore'' of exactly ten.
:* <code>@e[scores={myscore=!10..15}]</code> — Exclude any entities with a score in objective ''myscore'' of between ten and 15 (inclusive).
:* <code>@e[scores={myscore=!10..15}]</code> — Exclude any entities with a score in objective ''myscore'' of between ten and 15 (inclusive).
{{see also|Scoreboard#Objectives}}
{{MC/See also|Scoreboard#Objectives}}


===Selecting targets by tag===
===Selecting targets by tag===


: Filter target selection based on the entity's [[Minecraft:Scoreboard#Tags|scoreboard tags]]. Multiple tag arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
: Filter target selection based on the entity's scoreboard tags. Multiple tag arguments are allowed, and all arguments must be fulfilled for an entity to be selected.


: <code>[tag=<string>]</code> — Include only targets with the specified tag.
: <code>[tag=<string>]</code> — Include only targets with the specified tag.
Line 244: Line 244:
: <code>[tag=!]</code> — Include only targets that have at least one tag.
: <code>[tag=!]</code> — Include only targets that have at least one tag.


{{see also|Commands/tag}}
{{MC/See also|Commands/tag}}


{{anchor|Selecting targets by team}}
{{MC/Anchor|Selecting targets by team}}
===Selecting targets by team===
===Selecting targets by team===
{{exclusive|java|section=yes}}
{{MC/Exclusive|java|section=yes}}


: Filter target selection based on [[Minecraft:Scoreboard#Teams|teams]]. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
: Filter target selection based on teams. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
: <code>[team=<teamName>]</code> — Include only targets in the given team.
: <code>[team=<teamName>]</code> — Include only targets in the given team.
: <code>[team=!<teamName>]</code> — Exclude any targets in the given team.
: <code>[team=!<teamName>]</code> — Exclude any targets in the given team.
Line 256: Line 256:
: <code>[team=!]</code> — Exclude any targets not in a team.
: <code>[team=!]</code> — Exclude any targets not in a team.


{{see also|Commands/team}}
{{MC/See also|Commands/team}}


{{anchor|Selecting targets with a limit}}
{{MC/Anchor|Selecting targets with a limit}}


===Limiting and sorting target selection===
===Limiting and sorting target selection===
Line 265: Line 265:
: When using the variables <code>@p</code> and <code>@r</code>, this argument defaults to one. Applying the limiting argument to them may increase the number of nearest or random targets selected. When applying this argument to <code>@a</code> or <code>@e</code>, this argument returns only a limited number of targets. Cannot duplicate these arguments.
: When using the variables <code>@p</code> and <code>@r</code>, this argument defaults to one. Applying the limiting argument to them may increase the number of nearest or random targets selected. When applying this argument to <code>@a</code> or <code>@e</code>, this argument returns only a limited number of targets. Cannot duplicate these arguments.


: {{IN|java}}: <code>[limit=<value>,sort=(nearest|furthest|random|arbitrary)]</code> — Limit the number of targets, and specify selection priority.
: {{MC/In|java}}: <code>[limit=<value>,sort=(nearest|furthest|random|arbitrary)]</code> — Limit the number of targets, and specify selection priority.
:*<code>sort=nearest</code> — Sort by increasing distance. (Default for <code>@p</code>)
:*<code>sort=nearest</code> — Sort by increasing distance. (Default for <code>@p</code>)
:* <code>sort=furthest</code> — Sort by decreasing distance.
:* <code>sort=furthest</code> — Sort by decreasing distance.
Line 271: Line 271:
:* <code>sort=arbitrary</code> — Do not sort. This often returns the oldest entities first due to how the game stores entities internally, but no order is guaranteed. (Default for <code>@e</code>, <code>@a</code>)
:* <code>sort=arbitrary</code> — Do not sort. This often returns the oldest entities first due to how the game stores entities internally, but no order is guaranteed. (Default for <code>@e</code>, <code>@a</code>)


: {{IN|bedrock}}: <code>[c=<value>]</code> — Limit the number of targets.
: {{MC/In|bedrock}}: <code>[c=<value>]</code> — Limit the number of targets.
: For <code>@p</code>, <code>@a</code>, and <code>@e</code>, <code>[c=<value>]</code> selects only the specified number of targets by increasing distance from the selector's position. When <code>c</code> is negative, it reverses the order of targeting (for example, <code>@p[c=-1]</code> targets the furthest player). Inverse sorting does not work with <code>@r</code>.
: For <code>@p</code>, <code>@a</code>, and <code>@e</code>, <code>[c=<value>]</code> selects only the specified number of targets by increasing distance from the selector's position. When <code>c</code> is negative, it reverses the order of targeting (for example, <code>@p[c=-1]</code> targets the furthest player). Inverse sorting does not work with <code>@r</code>.


: Examples {{in|java}}:
: Examples {{MC/In|java}}:
:* <code>@a[limit=3,sort=nearest]</code> or <code>@p[limit=3]</code> — Select the nearest three players.
:* <code>@a[limit=3,sort=nearest]</code> or <code>@p[limit=3]</code> — Select the nearest three players.
:* <code>@a[limit=4,sort=furthest]</code> — Select the furthest four players.
:* <code>@a[limit=4,sort=furthest]</code> — Select the furthest four players.
:* <code>@a[limit=2,sort=random]</code> or <code>@r[limit=2]</code> — Select two players, chosen randomly.
:* <code>@a[limit=2,sort=random]</code> or <code>@r[limit=2]</code> — Select two players, chosen randomly.


: Examples {{in|bedrock}}:
: Examples {{MC/In|bedrock}}:
:* <code>@a[c=3]</code> — Select the nearest three players.
:* <code>@a[c=3]</code> — Select the nearest three players.
:* <code>@a[c=-4]</code> — Select the furthest four players.
:* <code>@a[c=-4]</code> — Select the furthest four players.
Line 286: Line 286:
===Selecting targets by experience level===
===Selecting targets by experience level===


: Filter target selection based on the entity's [[Minecraft:Experience|experience levels]]. This naturally filters out all non-player targets. Cannot duplicate these arguments.
: Filter target selection based on the entity's experience levels. This naturally filters out all non-player targets. Cannot duplicate these arguments.


: {{IN|java}}: <code>[level=<value>]</code> — Specifies the range of levels. [[Minecraft:Argument_types#minecraft:int_range|Integer ranges]] are supported to select a range of values.
: {{MC/In|java}}: <code>[level=<value>]</code> — Specifies the range of levels. Integer ranges are supported to select a range of values.


: {{IN|bedrock}}: <code>[l=<value>]</code> and <code>[lm=<value>]</code> — the maximum and minimum level range to search for, respectively.
: {{MC/In|bedrock}}: <code>[l=<value>]</code> and <code>[lm=<value>]</code> — the maximum and minimum level range to search for, respectively.


: Examples {{in|java}}:
: Examples {{MC/In|java}}:
:* <code>@a[level=10]</code> — Select all players who have exactly ten levels.
:* <code>@a[level=10]</code> — Select all players who have exactly ten levels.
:* <code>@a[level=8..16]</code> — Select all players who have between eight and 16 levels (inclusive).
:* <code>@a[level=8..16]</code> — Select all players who have between eight and 16 levels (inclusive).


: Examples {{in|bedrock}}:
: Examples {{MC/In|bedrock}}:
:* <code>@a[lm=10,l=10]</code> — Select all players who have exactly ten levels.
:* <code>@a[lm=10,l=10]</code> — Select all players who have exactly ten levels.
:* <code>@a[lm=8,l=16]</code> — Select all players who have between eight and 16 levels (inclusive).
:* <code>@a[lm=8,l=16]</code> — Select all players who have between eight and 16 levels (inclusive).


{{see also|Commands/experience}}
{{MC/See also|Commands/experience}}


===Selecting targets by game mode===
===Selecting targets by game mode===
: Filter target selection by [[Minecraft:Gameplay#Game_modes|game mode]]. This naturally filters out all non-player targets. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
: Filter target selection by game mode. This naturally filters out all non-player targets. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.


: {{IN|java}}:
: {{MC/In|java}}:
: <code>[gamemode=<gamemodeName>]</code> — Include only players in the given game mode.
: <code>[gamemode=<gamemodeName>]</code> — Include only players in the given game mode.
: <code>[gamemode=!<gamemodeName>]</code> — Exclude any players in the given game mode.
: <code>[gamemode=!<gamemodeName>]</code> — Exclude any players in the given game mode.


: {{IN|bedrock}}:
: {{MC/In|bedrock}}:
: <code>[m=<gamemodeName>]</code> — Include only players in the given game mode.
: <code>[m=<gamemodeName>]</code> — Include only players in the given game mode.
: <code>[m=!<gamemodeName>]</code> — Exclude any players in the given game mode.
: <code>[m=!<gamemodeName>]</code> — Exclude any players in the given game mode.


: Permitted values for <gamemodeName> are <code>spectator</code>, <code>survival</code>, <code>creative</code>, <code>adventure</code> and <code>default</code>{{only|bedrock|short=1}}. {{IN|bedrock}}, the shorthand values <code>s</code> and <code>0</code>, <code>c</code> and <code>1</code>, <code>a</code> and <code>2</code>, and <code>d</code> and <code>5</code> may be used for Survival mode, Creative mode, Adventure mode, and Default mode respectively.
: Permitted values for <gamemodeName> are <code>spectator</code>, <code>survival</code>, <code>creative</code>, <code>adventure</code> and <code>default</code>{{only|bedrock|short=1}}. {{MC/In|bedrock}}, the shorthand values <code>s</code> and <code>0</code>, <code>c</code> and <code>1</code>, <code>a</code> and <code>2</code>, and <code>d</code> and <code>5</code> may be used for Survival mode, Creative mode, Adventure mode, and Default mode respectively.


{{see also|Commands/gamemode}}
{{MC/See also|Commands/gamemode}}


===Selecting targets by name===  
===Selecting targets by name===  
Line 327: Line 327:
:Filter target selection based on the entity's rotation along the pitch axis, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down). Cannot duplicate these arguments.
:Filter target selection based on the entity's rotation along the pitch axis, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down). Cannot duplicate these arguments.


:{{IN|java}}: <code>[x_rotation=<value>]</code> — Specifies the range of x-rotation. [[Minecraft:Argument_types#minecraft:float_range|Float ranges]] are supported to select a specific range of angles.
:{{MC/In|java}}: <code>[x_rotation=<value>]</code> — Specifies the range of x-rotation. Float ranges are supported to select a specific range of angles.


:{{IN|bedrock}} <code>[rx=<value>]</code> and <code>[rxm=<value>]</code> — Specifies the maximum and minimum x-rotation, respectively.
:{{MC/In|bedrock}} <code>[rx=<value>]</code> and <code>[rxm=<value>]</code> — Specifies the maximum and minimum x-rotation, respectively.


:Examples {{in|java}}:
:Examples {{MC/In|java}}:
:*<code>@e[x_rotation=0]</code> — Select all entities that are looking directly at the horizon.
:*<code>@e[x_rotation=0]</code> — Select all entities that are looking directly at the horizon.
:*<code>@e[x_rotation=30..60]</code> — Select all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
:*<code>@e[x_rotation=30..60]</code> — Select all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
:*<code>@e[x_rotation=..0]</code> — Select all entities that are looking at or above the horizon.  
:*<code>@e[x_rotation=..0]</code> — Select all entities that are looking at or above the horizon.  


:Examples {{in|bedrock}}:
:Examples {{MC/In|bedrock}}:
:*<code>@e[rxm=0,rx=0]</code> — Selects all entities that are looking directly at the horizon.
:*<code>@e[rxm=0,rx=0]</code> — Selects all entities that are looking directly at the horizon.
:*<code>@e[rxm=30,rx=60]</code> — Selects all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
:*<code>@e[rxm=30,rx=60]</code> — Selects all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
Line 345: Line 345:
:Filter target selection based on the entity's rotation along the yaw axis, measured clockwise in degrees from due south (or the positive Z direction). Values vary from -180 (facing due north) to -90 (facing due east) to 0 (facing due south) to +90 (facing due west) to +180 (facing due north again). Cannot duplicate these arguments.
:Filter target selection based on the entity's rotation along the yaw axis, measured clockwise in degrees from due south (or the positive Z direction). Values vary from -180 (facing due north) to -90 (facing due east) to 0 (facing due south) to +90 (facing due west) to +180 (facing due north again). Cannot duplicate these arguments.


:{{IN|java}}: <code>[y_rotation=<value>]</code> — Specifies the range of y-rotation. [[Minecraft:Argument_types#minecraft:float_range|Float Ranges]] are supported to select a specific range of angles.
:{{MC/In|java}}: <code>[y_rotation=<value>]</code> — Specifies the range of y-rotation. Float Ranges are supported to select a specific range of angles.


:{{IN|bedrock}}: <code>[ry=<value>]</code> and <code>[rym=<value>]</code> — Specifies the maximum and minimum y-rotation values, respectively.
:{{MC/In|bedrock}}: <code>[ry=<value>]</code> and <code>[rym=<value>]</code> — Specifies the maximum and minimum y-rotation values, respectively.


:Examples {{in|java}}:
:Examples {{MC/In|java}}:
:*<code>@e[y_rotation=0]</code> — Select all entities that are facing due south.
:*<code>@e[y_rotation=0]</code> — Select all entities that are facing due south.
:* <code>@e[y_rotation=-90..0]</code> — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
:* <code>@e[y_rotation=-90..0]</code> — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
:*<code>@e[y_rotation=0..180]</code> — Select all entities that are not facing at all east.
:*<code>@e[y_rotation=0..180]</code> — Select all entities that are not facing at all east.


:Examples {{in|bedrock}}:
:Examples {{MC/In|bedrock}}:
:*<code>@e[rym=0,ry=0]</code> — Select all entities that are facing due south.
:*<code>@e[rym=0,ry=0]</code> — Select all entities that are facing due south.
:*<code>@e[rym=-90,ry=0]</code> — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
:*<code>@e[rym=-90,ry=0]</code> — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
Line 361: Line 361:
===Selecting targets by type===  
===Selecting targets by type===  


:Filter target selection based on the entity's identifier. The given entity type must be a valid [[Minecraft:Resource location|entity ID]] or [[Minecraft:Tag#Entity_type_tags|entity type tag]]{{only|java}} used to identify different types of entities internally. The namespace can be left out if the ID is within the {{cd|minecraft}} namespace. Entity IDs or tags are case-sensitive. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can. {{IN|java}}, using this argument with <code>@a</code>, <code>@p</code> or <code>@r</code> is not allowed.
:Filter target selection based on the entity's identifier. The given entity type must be a valid entity ID or entity type tag{{only|java}} used to identify different types of entities internally. The namespace can be left out if the ID is within the {{MC/Cd|minecraft}} namespace. Entity IDs or tags are case-sensitive. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can. {{MC/In|java}}, using this argument with <code>@a</code>, <code>@p</code> or <code>@r</code> is not allowed.


:<code>[type=<entityType>]</code> — Include only targets of the specified entity type or tag.
:<code>[type=<entityType>]</code> — Include only targets of the specified entity type or tag.
:<code>[type=!<entityType>]</code> — Exclude any targets of the specified entity type or tag.
:<code>[type=!<entityType>]</code> — Exclude any targets of the specified entity type or tag.


:{{IN|java}}, the option <code>type=<entityType></code> (without <code>!</code> symbol) can appear only once, and <code>type=!<entityType></code> cannot appear with it. If <code>type=<entityType></code> does not exist, then <code>type=!<entityType></code> may appear multiple times.
:{{MC/In|java}}, the option <code>type=<entityType></code> (without <code>!</code> symbol) can appear only once, and <code>type=!<entityType></code> cannot appear with it. If <code>type=<entityType></code> does not exist, then <code>type=!<entityType></code> may appear multiple times.
:Examples:
:Examples:
:* <code>@e[type=creeper]</code> - Include only creepers.
:* <code>@e[type=creeper]</code> - Include only creepers.
Line 373: Line 373:
:* <code>@e[type=!creeper, type=!pig]</code> - Exclude all creepers and pigs.
:* <code>@e[type=!creeper, type=!pig]</code> - Exclude all creepers and pigs.


{{anchor|Selecting targets by family}}
{{MC/Anchor|Selecting targets by family}}


===Selecting targets by family===
===Selecting targets by family===
{{exclusive|bedrock|section=yes}}
{{MC/Exclusive|bedrock|section=yes}}


:Filter target selection based on the entity's [https://learn.microsoft.com/en-us/minecraft/creator/reference/content/entityreference/examples/entitycomponents/minecraftcomponent_type_family type_family] behavior component. Default values used by the vanilla behavior pack include among others more broad terms like <code>mob</code> and <code>inanimate</code>, as well as more specific families like <code>zombie</code> and <code>skeleton</code>, and single-mob families like <code>wandering_trader</code> and <code>creeper</code>. Multiple family arguments are allowed, and all arguments must be fulfilled for an entity to be selected.{{main|family}}
:Filter target selection based on the entity's [https://learn.microsoft.com/en-us/minecraft/creator/reference/content/entityreference/examples/entitycomponents/minecraftcomponent_type_family type_family] behavior component. Default values used by the vanilla behavior pack include among others more broad terms like <code>mob</code> and <code>inanimate</code>, as well as more specific families like <code>zombie</code> and <code>skeleton</code>, and single-mob families like <code>wandering_trader</code> and <code>creeper</code>. Multiple family arguments are allowed, and all arguments must be fulfilled for an entity to be selected.{{MC/Main|family}}


:<code>[family=<family>]</code> — Include only targets in the specified type family.
:<code>[family=<family>]</code> — Include only targets in the specified type family.
Line 387: Line 387:
:*<code>@e[family=monster,family=undead]</code> — Select all monsters that are also undead (that includes monsters like zombies and skeletons, but not creepers, spiders or endermen).
:*<code>@e[family=monster,family=undead]</code> — Select all monsters that are also undead (that includes monsters like zombies and skeletons, but not creepers, spiders or endermen).


{{anchor|Selecting targets by nbt}}
{{MC/Anchor|Selecting targets by nbt}}


===Selecting targets by NBT data===
===Selecting targets by NBT data===
{{exclusive|java|section=yes}}
{{MC/Exclusive|java|section=yes}}


:Filter target selection based on the entity's NBT data. The NBT data is written in its [[Minecraft:NBT_format|SNBT format]]. Duplicate nbt arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
:Filter target selection based on the entity's NBT data. The NBT data is written in its SNBT format. Duplicate nbt arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
:See [[Minecraft:NBT format#Testing NBT tags]] for more infomation about this.
:See NBT format for more infomation about this.
:Note that this selector argument should be used with care, as accessing NBT data is a heavy process for the CPU.
:Note that this selector argument should be used with care, as accessing NBT data is a heavy process for the CPU.
:<code>[nbt=<compoundTag>]</code> — Include only targets with the specified NBT data.
:<code>[nbt=<compoundTag>]</code> — Include only targets with the specified NBT data.
Line 403: Line 403:
:*<code>@e[nbt={Tags:[a,b]}]</code> is the same as <code>@e[tag=a,tag=b]</code>. The latter is simpler and reduces CPU load.
:*<code>@e[nbt={Tags:[a,b]}]</code> is the same as <code>@e[tag=a,tag=b]</code>. The latter is simpler and reduces CPU load.


{{anchor|Selecting targets by advancements}}
{{MC/Anchor|Selecting targets by advancements}}
===Selecting targets by advancements===
===Selecting targets by advancements===
{{exclusive|java|section=yes}}
{{MC/Exclusive|java|section=yes}}


:Filter target selection based on the entity's [[Minecraft:Advancement|advancements]]. This naturally filters out all non-player targets. All advancements are in a single object, with a list of individual advancement IDs between the braces afterward. The values are [[Minecraft:Argument_types#brigadier:bool|true or false]]. For advancements with one criterion, testing for that criterion always gives the same results as testing for the advancement. Cannot duplicate this argument.
:Filter target selection based on the entity's advancements. This naturally filters out all non-player targets. All advancements are in a single object, with a list of individual advancement IDs between the braces afterward. The values are true or false. For advancements with one criterion, testing for that criterion always gives the same results as testing for the advancement. Cannot duplicate this argument.
:<code>[advancements={<''resource location''>=<bool>}]</code> — Include only players with the specified advancements and values.
:<code>[advancements={<''resource location''>=<bool>}]</code> — Include only players with the specified advancements and values.
:<code>[advancements={<''resource location''>={<criteria>=<bool>}}]</code> — Include only players with the specified advancement's criteria.
:<code>[advancements={<''resource location''>={<criteria>=<bool>}}]</code> — Include only players with the specified advancement's criteria.
Line 416: Line 416:
:*<code><nowiki>@a[advancements={adventure/kill_all_mobs={witch=true}}]</nowiki></code> — Include only players who have killed a witch, for the advancement <samp>minecraft:adventure/kill_all_mobs</samp>.
:*<code><nowiki>@a[advancements={adventure/kill_all_mobs={witch=true}}]</nowiki></code> — Include only players who have killed a witch, for the advancement <samp>minecraft:adventure/kill_all_mobs</samp>.


{{see also|Commands/advancement}}
{{MC/See also|Commands/advancement}}


{{anchor|Selecting targets by predicate}}
{{MC/Anchor|Selecting targets by predicate}}
===Selecting targets by predicate===
===Selecting targets by predicate===
{{exclusive|java|section=yes}}
{{MC/Exclusive|java|section=yes}}


:Filter target selection by [[Minecraft:Predicate|predicates]]. The given values must be a valid predicate represented by a resource location. Duplicate predicate arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
:Filter target selection by predicates. The given values must be a valid predicate represented by a resource location. Duplicate predicate arguments are allowed, and all arguments must be fulfilled for an entity to be selected.


:<code>[predicate=<''resource location''>]</code> — Include only targets that match the specified predicate.
:<code>[predicate=<''resource location''>]</code> — Include only targets that match the specified predicate.
:<code>[predicate=!<''resource location''>]</code> — Exclude any targets that match the specified predicate.
:<code>[predicate=!<''resource location''>]</code> — Exclude any targets that match the specified predicate.


{{anchor|Selecting targets by item}}
{{MC/Anchor|Selecting targets by item}}
===Selecting targets by item===
===Selecting targets by item===
{{exclusive|bedrock|section=yes}}
{{MC/Exclusive|bedrock|section=yes}}


:Filter target selection based on whether the entity has the specified items. The given values must be enclosed by square brackets or braces. Cannot duplicate this argument, but multiple items can be specified with square brackets.
:Filter target selection based on whether the entity has the specified items. The given values must be enclosed by square brackets or braces. Cannot duplicate this argument, but multiple items can be specified with square brackets.
Line 455: Line 455:
:* Example using location: <code>@s[hasitem={item=stick,location=slot.weapon.mainhand}]</code>
:* Example using location: <code>@s[hasitem={item=stick,location=slot.weapon.mainhand}]</code>


{{anchor|Selecting targets by permission}}
{{MC/Anchor|Selecting targets by permission}}
===Selecting targets by permission===
===Selecting targets by permission===
{{exclusive|bedrock|section=yes}}
{{MC/Exclusive|bedrock|section=yes}}


: <code>[haspermission={<permission>=<state>,...}]</code> — Filter target selection based on the player permissions status. All tested permissions are in a single object, separated by commas. Cannot duplicate this argument.
: <code>[haspermission={<permission>=<state>,...}]</code> — Filter target selection based on the player permissions status. All tested permissions are in a single object, separated by commas. Cannot duplicate this argument.
Line 465: Line 465:
:*<code>@a[haspermission={camera=disabled,movement=enabled}]</code> — Include only players who have the camera permission disabled and the movement permission enabled.
:*<code>@a[haspermission={camera=disabled,movement=enabled}]</code> — Include only players who have the camera permission disabled and the movement permission enabled.


{{see also|Commands/inputpermission}}
{{MC/See also|Commands/inputpermission}}


{{anchor|Selecting targets by property}}
{{MC/Anchor|Selecting targets by property}}
===Selecting targets by property===
===Selecting targets by property===
{{exclusive|bedrock|section=yes}}
{{MC/Exclusive|bedrock|section=yes}}
:Filter target selection based on the entity's property. All tested properties are in a single object, separated by commas. Cannot duplicate this argument.
:Filter target selection based on the entity's property. All tested properties are in a single object, separated by commas. Cannot duplicate this argument.


Line 486: Line 486:
:List of entity properties:
:List of entity properties:
{{collapse|content=
{{collapse|content=
*{{nbt|string|minecraft:armadillo_state}}: {{cd|unrolled}}, {{cd|rolled_up}}, {{cd|rolled_up_peeking}}, {{cd|rolled_up_relaxing}}, or {{cd|rolled_up_unrolling}} &mdash; Applies to {{EntityLink|Armadillo|armadillos}}.
*{{MC/Nbt|string|minecraft:armadillo_state}}: {{MC/Cd|unrolled}}, {{MC/Cd|rolled_up}}, {{MC/Cd|rolled_up_peeking}}, {{MC/Cd|rolled_up_relaxing}}, or {{MC/Cd|rolled_up_unrolling}} &mdash; Applies to {{MC/Entitylink|Armadillo|armadillos}}.
*{{nbt|bool|minecraft:can_move}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Happy Ghast|happy ghasts}}.
*{{MC/Nbt|bool|minecraft:can_move}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Happy Ghast|happy ghasts}}.
*{{nbt|string|minecraft:chest_interaction}}: {{cd|none}}, {{cd|take}}, {{cd|take_fail}}, {{cd|put}}, or {{cd|put_fail}} &mdash; Applies to {{EntityLink|Copper Golem|copper golems}}.
*{{MC/Nbt|string|minecraft:chest_interaction}}: {{MC/Cd|none}}, {{MC/Cd|take}}, {{MC/Cd|take_fail}}, {{MC/Cd|put}}, or {{MC/Cd|put_fail}} &mdash; Applies to {{MC/Entitylink|Copper Golem|copper golems}}.
*{{nbt|string|minecraft:climate_variant}}: {{cd|temperate}}, {{cd|warm}}, or {{cd|cold}} &mdash; Applies to {{EntityLink|Cow|cows}}, {{EntityLink|Chicken|chickens}}, {{EntityLink|Pig|pigs}}, and {{EntityLink|Egg|thrown eggs}}.
*{{MC/Nbt|string|minecraft:climate_variant}}: {{MC/Cd|temperate}}, {{MC/Cd|warm}}, or {{MC/Cd|cold}} &mdash; Applies to {{MC/Entitylink|Cow|cows}}, {{MC/Entitylink|Chicken|chickens}}, {{MC/Entitylink|Pig|pigs}}, and {{MC/Entitylink|Egg|thrown eggs}}.
*{{nbt|string|minecraft:creaking_state}}: {{cd|neutral}}, {{cd|hostile_observed}}, {{cd|hostile_unobserved}}, {{cd|twitching}}, or {{cd|crumbling}} &mdash; Applies to {{EntityLink|Creaking|creakings}}.
*{{MC/Nbt|string|minecraft:creaking_state}}: {{MC/Cd|neutral}}, {{MC/Cd|hostile_observed}}, {{MC/Cd|hostile_unobserved}}, {{MC/Cd|twitching}}, or {{MC/Cd|crumbling}} &mdash; Applies to {{MC/Entitylink|Creaking|creakings}}.
*{{nbt|int|minecraft:creaking_swaying_ticks}}: {{cd|0}} to {{cd|6}} &mdash; Applies to {{EntityLink|Creaking|creakings}}.
*{{MC/Nbt|int|minecraft:creaking_swaying_ticks}}: {{MC/Cd|0}} to {{MC/Cd|6}} &mdash; Applies to {{MC/Entitylink|Creaking|creakings}}.
*{{nbt|bool|minecraft:has_increased_max_health}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Wolf|wolves}}.
*{{MC/Nbt|bool|minecraft:has_increased_max_health}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Wolf|wolves}}.
*{{nbt|bool|minecraft:has_nectar}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Bee|bees}}.
*{{MC/Nbt|bool|minecraft:has_nectar}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Bee|bees}}.
*{{nbt|bool|minecraft:is_armorable}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Wolf|wolves}}.
*{{MC/Nbt|bool|minecraft:is_armorable}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Wolf|wolves}}.
*{{nbt|bool|minecraft:is_playing_idle_ground_sound}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Breeze|breezes}}.
*{{MC/Nbt|bool|minecraft:is_playing_idle_ground_sound}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Breeze|breezes}}.
*{{nbt|bool|minecraft:is_waxed}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Copper Golem|copper golems}}.
*{{MC/Nbt|bool|minecraft:is_waxed}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Copper Golem|copper golems}}.
*{{nbt|string|minecraft:oxidation_level}}: {{cd|unoxidized}}, {{cd|exposed}}, {{cd|weathered}}, or {{cd|oxidized}} &mdash; Applies to {{EntityLink|Copper Golem|copper golems}}.
*{{MC/Nbt|string|minecraft:oxidation_level}}: {{MC/Cd|unoxidized}}, {{MC/Cd|exposed}}, {{MC/Cd|weathered}}, or {{MC/Cd|oxidized}} &mdash; Applies to {{MC/Entitylink|Copper Golem|copper golems}}.
*{{nbt|string|minecraft:sound_variant}}: {{cd|default}}, {{cd|big}}, {{cd|cute}}, {{cd|grumpy}}, {{cd|mad}}, {{cd|puglin}}, or {{cd|sad}} &mdash; Applies to {{EntityLink|Wolf|wolves}}.
*{{MC/Nbt|string|minecraft:sound_variant}}: {{MC/Cd|default}}, {{MC/Cd|big}}, {{MC/Cd|cute}}, {{MC/Cd|grumpy}}, {{MC/Cd|mad}}, {{MC/Cd|puglin}}, or {{MC/Cd|sad}} &mdash; Applies to {{MC/Entitylink|Wolf|wolves}}.
*{{nbt|bool|minecraft:was_upgraded_to_1_21_100}}: {{cd|true}} or {{cd|false}} &mdash; Applies to {{EntityLink|Wolf|wolves}}.
*{{MC/Nbt|bool|minecraft:was_upgraded_to_1_21_100}}: {{MC/Cd|true}} or {{MC/Cd|false}} &mdash; Applies to {{MC/Entitylink|Wolf|wolves}}.
}}
}}


Line 509: Line 509:


A player-type selector is a selector that can only select players, including:
A player-type selector is a selector that can only select players, including:
*{{cd|@e, @n}} with <code>type=player</code>.
*{{MC/Cd|@e, @n}} with <code>type=player</code>.
*{{cd|@a, @p}} (without {{cd|type}} argument {{in|bedrock}}).
*{{MC/Cd|@a, @p}} (without {{MC/Cd|type}} argument {{MC/In|bedrock}}).
*{{cd|@r}} with <code>type=player</code>{{only|bedrock}} or without {{cd|type}} argument.
*{{MC/Cd|@r}} with <code>type=player</code>{{only|bedrock}} or without {{MC/Cd|type}} argument.


{{IN|je}}, if a command argument requires a player type selector, but the entered argument is not in player type, the command is unparseable.
{{MC/In|je}}, if a command argument requires a player type selector, but the entered argument is not in player type, the command is unparseable.


{{IN|be}}, if a command argument requires a player type selector, but the entered argument is not in player type, the command is parseable but fails.
{{MC/In|be}}, if a command argument requires a player type selector, but the entered argument is not in player type, the command is parseable but fails.


===Single type===
===Single type===
{{exclusive|java|section=1}}
{{MC/Exclusive|java|section=1}}
Some command arguments require a single-type selector, while some require a multiple-type selector.
Some command arguments require a single-type selector, while some require a multiple-type selector.


Line 524: Line 524:


A single-type selector is a selector that can only select one target, including:  
A single-type selector is a selector that can only select one target, including:  
*{{cd|@a, @e}} with <code>limit=1</code>.
*{{MC/Cd|@a, @e}} with <code>limit=1</code>.
*{{cd|@s}} without {{cd|limit}} argument.
*{{MC/Cd|@s}} without {{MC/Cd|limit}} argument.
*{{cd|@p, @r}} without {{cd|limit}} argument or with <code>limit=1</code>.
*{{MC/Cd|@p, @r}} without {{MC/Cd|limit}} argument or with <code>limit=1</code>.


If a command argument requires a single-type selector, but the entered argument is not in single-type, the command is unparseable.
If a command argument requires a single-type selector, but the entered argument is not in single-type, the command is unparseable.
Line 537: Line 537:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|java}}
|{{MC/HistoryLine|java}}
|{{HistoryLine||1.4.2|dev=12w32a|Added target selectors.}}
|{{MC/HistoryLine||1.4.2|dev=12w32a|Added target selectors.}}
|{{HistoryLine|||dev=12w38a|Added target selector arguments with <code>x</code>, <code>y</code>, <code>z</code>, <code>r</code>, <code>m</code> and <code>c</code>.}}
|{{MC/HistoryLine|||dev=12w38a|Added target selector arguments with <code>x</code>, <code>y</code>, <code>z</code>, <code>r</code>, <code>m</code> and <code>c</code>.}}
|{{HistoryLine|||dev=12w39b|Added <code>l</code> and <code>lm</code> target selector arguments for indicating players with a maximum level, and minimum level, respectively.|Added the <code>rm</code> target selector argument for indicating players from a minimum distance.}}
|{{MC/HistoryLine|||dev=12w39b|Added <code>l</code> and <code>lm</code> target selector arguments for indicating players with a maximum level, and minimum level, respectively.|Added the <code>rm</code> target selector argument for indicating players from a minimum distance.}}
|{{HistoryLine||?|Added the <code>name</code> target selector argument.}}<!--This works in 1.5 but may have been introduced earlier -->
|{{MC/HistoryLine||?|Added the <code>name</code> target selector argument.}}<!--This works in 1.5 but may have been introduced earlier -->
|{{HistoryLine||1.5|dev=?|Added the <code>score_objective</code> and <code>score_objective_min</code> target selector arguments, where <code>objective</code> should be replaced with the objective to test.|Added the <code>team</code> target selector argument.}}
|{{MC/HistoryLine||1.5|dev=?|Added the <code>score_objective</code> and <code>score_objective_min</code> target selector arguments, where <code>objective</code> should be replaced with the objective to test.|Added the <code>team</code> target selector argument.}}
|{{HistoryLine||1.8|dev=14w02a|Added the <code>@e</code> target selector variable.|Added the <code>type</code> target selector argument.}}
|{{MC/HistoryLine||1.8|dev=14w02a|Added the <code>@e</code> target selector variable.|Added the <code>type</code> target selector argument.}}
|{{HistoryLine|||dev=14w03a|Added <code>dx</code>, <code>dy</code>, and <code>dz</code> target selector arguments.}}
|{{MC/HistoryLine|||dev=14w03a|Added <code>dx</code>, <code>dy</code>, and <code>dz</code> target selector arguments.}}
|{{HistoryLine|||dev=14w07a|Added <code>rx</code>, <code>rxm</code>, <code>ry</code> and <code>rym</code> target selector arguments.}}
|{{MC/HistoryLine|||dev=14w07a|Added <code>rx</code>, <code>rxm</code>, <code>ry</code> and <code>rym</code> target selector arguments.}}
|{{HistoryLine||1.9|dev=15w32b|Added the <code>tag</code> target selector argument.}}
|{{MC/HistoryLine||1.9|dev=15w32b|Added the <code>tag</code> target selector argument.}}
|{{HistoryLine|||dev=16w02a|The <code>m</code> selector now accepts the standard literal gamemode values and abbreviations, such as <code>a</code> and <code>adventure</code>, and these may be negated as well.}}
|{{MC/HistoryLine|||dev=16w02a|The <code>m</code> selector now accepts the standard literal gamemode values and abbreviations, such as <code>a</code> and <code>adventure</code>, and these may be negated as well.}}
|{{HistoryLine||1.11|dev=16w38a|Removed implicit target selectors (for example, <code>@e[167,28,454]</code>).
|{{HistoryLine||1.11|dev=16w38a|Removed implicit target selectors (for example, <code>@e[167,28,454]</code>).
|Invalid target selectors (such as <code>@e[Type{{=}}creeper]</code>, <code>@e[asdf{{=}}nonexistent]</code>, and <code>@e[malformed]</code>) now generate an error instead of being silently ignored.}}
|Invalid target selectors (such as <code>@e[Type{{=}}creeper]</code>, <code>@e[asdf{{=}}nonexistent]</code>, and <code>@e[malformed]</code>) now generate an error instead of being silently ignored.}}
|{{HistoryLine||1.12|dev=17w16b|Added the <code>@s</code> target selector variable.}}
|{{MC/HistoryLine||1.12|dev=17w16b|Added the <code>@s</code> target selector variable.}}
|{{HistoryLine||1.13|dev=17w45a|Target selector arguments can now be quoted.|The shorthand argument names have been renamed.
|{{HistoryLine||1.13|dev=17w45a|Target selector arguments can now be quoted.|The shorthand argument names have been renamed.
*<code>m</code> -> <code>gamemode</code>
*<code>m</code> -> <code>gamemode</code>
Line 568: Line 568:
|Specifying scores now looks like <code>scores{{=}}{foo{{=}}1,bar{{=}}1..5}</code>.
|Specifying scores now looks like <code>scores{{=}}{foo{{=}}1,bar{{=}}1..5}</code>.
}}
}}
|{{HistoryLine|||dev=17w45b|Added the <code>nbt</code> target selector argument.}}
|{{MC/HistoryLine|||dev=17w45b|Added the <code>nbt</code> target selector argument.}}
|{{HistoryLine||1.15|dev=19w38a|Added the <code>predicate</code> target selector argument.}}
|{{MC/HistoryLine||1.15|dev=19w38a|Added the <code>predicate</code> target selector argument.}}
|{{HistoryLine||1.21|dev=24w21a|Added the <code>@n</code> selector which selects the nearest entity.}}
|{{MC/HistoryLine||1.21|dev=24w21a|Added the <code>@n</code> selector which selects the nearest entity.}}
|{{HistoryLine|||dev=pre1|<code>@n</code> no longer selects dying entities.<ref>{{bug|MC-272490}}</ref>}}
|{{HistoryLine|||dev=pre1|<code>@n</code> no longer selects dying entities.<ref>{{bug|MC-272490}}</ref>}}
|{{HistoryLine||1.21.5|dev=25w05a|The <code>team</code> argument can now select non-living entities.<ref>{{bug|MC-108495}}</ref>}}
|{{HistoryLine||1.21.5|dev=25w05a|The <code>team</code> argument can now select non-living entities.<ref>{{bug|MC-108495}}</ref>}}
Line 577: Line 577:
=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{HistoryLine|pocket alpha}}
|{{MC/HistoryLine|pocket alpha}}
|{{HistoryLine||v0.16.0|dev=build 1|Added target selectors along with [[Minecraft:Commands]].}}
|{{MC/HistoryLine||v0.16.0|dev=build 1|Added target selectors along with [[Minecraft:Commands]].}}
|{{HistoryLine|bedrock}}
|{{MC/HistoryLine|bedrock}}
|{{HistoryLine||1.17.10|dev=beta 1.17.10.22|Added the {{cd|@initiator}} target selector variable.}}
|{{HistoryLine||1.17.10|dev=beta 1.17.10.22|Added the {{MC/Cd|@initiator}} target selector variable.}}
|{{HistoryLine||1.18.30|dev=beta 1.18.20.21|Added the {{cd|hasitem}} target selector argument.}}
|{{HistoryLine||1.18.30|dev=beta 1.18.20.21|Added the {{MC/Cd|hasitem}} target selector argument.}}
|{{HistoryLine||1.19.80|dev=Preview 1.19.80.21|Added the {{cd|haspermission}} target selector argument.}}
|{{HistoryLine||1.19.80|dev=Preview 1.19.80.21|Added the {{MC/Cd|haspermission}} target selector argument.}}
|{{HistoryLine||1.20.70|dev=Preview 1.20.70.21|Added the {{cd|has_property}} target selector argument.}}
|{{HistoryLine||1.20.70|dev=Preview 1.20.70.21|Added the {{MC/Cd|has_property}} target selector argument.}}
|{{HistoryLine||1.21.100|dev=Preview 1.21.100.21|Added the <code>@n</code> selector which selects the nearest entity.}}
|{{MC/HistoryLine||1.21.100|dev=Preview 1.21.100.21|Added the <code>@n</code> selector which selects the nearest entity.}}
}}
}}


==Issues==
==Issues==


{{issue list}}
{{MC/Issue list}}


==See also ==
==See also ==
*[[Minecraft:Commands]]
*[[Minecraft:Commands]]
*[[Minecraft:Entity format]]
*Entity format


== References ==
== References ==
{{reflist}}
{{MC/Reflist}}


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


[[Category:Server]]
[[Category:Server]]
[[Category:Commands]]
[[Category:Commands]]


[[Minecraft:de:Befehl#Ziel-Auswahl]]
de:Befehl
[[Minecraft:es:Comandos]]
es:Comandos
[[Minecraft:fr:Commandes]]
fr:Commandes
[[Minecraft:hu:Szerverparancsok]]
hu:Szerverparancsok
[[Minecraft:it:Comandi]]
it:Comandi
[[Minecraft:ja:ターゲットセレクター]]
ja:ターゲットセレクター
[[Minecraft:ko:명령어]]
ko:명령어
[[Minecraft:nl:Opdrachten]]
nl:Opdrachten
[[Minecraft:pl:Polecenia]]
pl:Polecenia
[[Minecraft:pt:Seletores de destino]]
pt:Seletores de destino
[[Minecraft:ru:Команды консоли]]
ru:Команды консоли
[[Minecraft:th:คำสั่ง]]
th:คำสั่ง
[[Minecraft:tr:Komutlar]]
tr:Komutlar
[[Minecraft:uk:Команди консолі]]
uk:Команди консолі
[[Minecraft:zh:目标选择器]]
zh:目标选择器

Latest revision as of 21:02, 9 April 2026

Template:Hatnote Target selectors are used in Minecraft:commands to select players and entities arbitrarily, without needing to specify an exact player name or a UUID. One or more entities can be selected with a target selector variable, and targets can be filtered from the selection based on certain criteria using the target selector arguments.

Template:TOC limit

Target selector variables

Summary of target selector variables
Variable Selects
@p the nearest player
@r a random player
@a all players
@e all entities
@s the entity executing the command
@n the nearest entity
@c the player's agentTemplate:Only
@v all agentsTemplate:Only
@initiator the player who clicks an Minecraft:NPC dialogue buttonTemplate:Only

A target selector variable identifies the broad category of targets to select. There are six in Java Edition, seven in Bedrock Edition and nine in Template:Editions:

@p
Selects the nearest player from the command's execution. If there are multiple nearest players, caused by them being precisely the same distance away, the player who most recently joined the server is selected.
in Template:Editions, @p selects only players who are alive.
@n
Selects the nearest alive entity from the command's execution.
@r
Selects a random online player.
In
  1. REDIRECT Template:Edition

Template:Rcat, you can use @r to select non-player entities via the type selector argument; in Template:Editions, to select a random entity, use @e[sort=random,limit=1] or @n[sort=random] instead.

in Template:Editions, @r can select only entities who are alive.
@a
Selects every online player (alive or dead).
@e
Selects all alive entities in loaded chunks, and all alive online players.
@s
Selects the entity (alive or not) that the command was executed as. It does not select anything if the command was not ran as an entity (e.g. from a command block or server console).
@cTemplate:Only
Selects the player's agent only.
@vTemplate:Only
Selects all agents. Works only if more than one agent exists.
@initiatorTemplate:Only
Selects the player who interacts with a button in a JSON Minecraft:NPC dialogue.

Target selector arguments

Summary of target selector arguments
Selection by Spatial Properties
Argument(s) Selection criteria
x, y, z coordinate
distanceTemplate:Only
r, rmTemplate:Only
distance
dx, dy, dz volume dimensions
x_rotationTemplate:Only
rx,rxmTemplate:Only
vertical rotation (pitch)
y_rotationTemplate:Only
ry,rymTemplate:Only
horizontal rotation (yaw)
Selection by Scoreboard Values
Argument(s) Selection criteria
scores scores
tag tag
team Template:Only team name
Selection by Entity Species
Argument(s) Selection criteria
name entity name
type entity type
familyTemplate:Only entity family
predicateTemplate:Only predicate
Selection by Entity Data
Argument(s) Selection criteria
nbtTemplate:Only nbt
hasitemTemplate:Only item
has_propertyTemplate:Only property
Selection by Player Data
Argument(s) Selection criteria
levelTemplate:Only
l,lmTemplate:Only
experience level
gamemodeTemplate:Only
mTemplate:Only
game mode
advancementsTemplate:Only advancements
haspermissionTemplate:Only permission
Selection by Traits
Argument(s) Selection criteria
limit,sortTemplate:Only
cTemplate:Only
limit

After a target selector, optional arguments can be used to narrow down the set of targets to a group that also matches certain criteria. When used with @a or @e, arguments narrow down the targets from the full list to a specific group. When used with @p or @r, the nearest or random player is selected from the group. When used with @s, the player using the command is targeted only if they would be in the narrowed group.

Argument-value pairs appear within square brackets after the target selector variable, separated by commas:

@<variable>[<argument>=<value>,<argument>=<value>,...].

in Template:Editions, arguments and values are case-sensitive. Spaces are allowed around the brackets, equal signs, and commas, except in Template:Editions between the target variable and the first bracket. Commas must be used to separate argument-value pairs.

If there are multiple argument-value pairs, they all must be satisfied to add a potential target to the group. (In other words, they are AND-ed together).

Position arguments

[x=<value>,y=<value>,z=<value>] — Define a position in the world that the selector starts at, for use with the distance argument, the volume arguments, or the sort and limit arguments. Using these arguments alone does not restrict the entities found (except in Template:Editions), and affect only the sorting of targets. Cannot duplicate any one of these three arguments.
The positional components are doubles, allowing for values like 12.34. in Template:Editions they are not center-corrected, meaning x=0 is not corrected to x=0.5. in Template:Editions, if distance or volume arguments are not used, positions that are written as integers are center-corrected, x=0 becomes x=0.5. To avoid this, use x=0.0 instead.
in Template:Editions, tilde notation is available for selector argument coordinates. Note: Caret notation is not.
in Template:Editions, these arguments limit the search of entities to the current dimension. For example /execute in overworld as @e[x=0] will select only entities that are in the overworld.

Selecting targets by distance

Filter target selection based on their Euclidean distances from some point, searching for the target's feet (a point at the bottom of the center of their hitbox). If the positional arguments are left undefined, radius is calculated relative to the position of the command's execution. This argument limits the search of entities to the current dimension. Cannot duplicate these arguments.
in Template:Editions: [distance=<value>] — Specifies the range of distance. Float ranges are supported to select a specific region. Only unsigned values are allowed.
in Template:Editions: [r=<value>] and [rm=<value>] — Specifies the maximum and minimum range to find entities, respectively. Only unsigned values are allowed.
Examples in Template:Editions:
  • @e[distance=10..] — Target all entities more than ten blocks away.
  • @e[distance=..10] — Target all entities less than ten blocks away.
  • @e[distance=10] — Target all entities exactly ten blocks away.
  • @e[distance=8..16] — Target all entities more than eight blocks, but less than 16 blocks away (inclusive).
Examples in Template:Editions:
  • @e[r=10] — Target all entities that are ten or fewer blocks away.
  • @e[rm=10] — Target all entities that are ten or more blocks away.
  • @e[rm=10,r=10] — Target all entities exactly ten blocks away.
  • @e[rm=8,r=16] — Target all entities from 8 to 16 blocks away.

Selecting targets by volume

[dx=<value>,dy=<value>,dz=<value>] — Filter target selection based on their x-difference, y-difference, and z-difference from some point, as measured by entities' hitboxes. Cannot duplicate any one of these three arguments.
Numerically, this can be interpreted as creating a cuboid volume from the initial position (x,y,z) to (x+dx,y+dy,z+dz) but with the vector (1,1,1) added to the x-most, y-most, z-most corner (the upper south-east corner). Because of this, the volume to check can never be smaller than a cube with a side length of 1, and no single dimension of the volume can be less than 1. Then, all entities whose hitboxes at least partially intersect with that volume are selected. If the positional arguments are left out, the selection is interpreted as originating from the position of the command's execution. Any values are allowed, including signed and fractional numbers.
If all of the values are whole numbers, this can be interpreted as creating a volume of blocks from the initial position (x y z) to the delta position (x+dx y+dy z+dz)) and selecting any entity whose hitbox intersects with those blocks. So, if you have built a cuboid of blocks in the world, you can subtract the coordinates of one corner block from the coordinates of the opposite corner block to get the dx, dy, and dz values for selecting those entities.
Note that dx, dy, and dz specify signed differences from the given coordinate. They do not specify a separate coordinate, nor do they extend in both the positive and negative directions as you might expect from a position predicate.
Additionally, when only one or two volume arguments are present, any that are not specified are assumed to be set to zero. For example, @a[dx=15] is equivalent to @a[dx=15,dy=0,dz=0].
Examples:
  • @e[x=1,y=2,z=3,dx=0,dy=0,dz=0] — Select all entities whose hitbox intersects with the block at 1 2 3.
  • @e[x=1,y=2,z=3,dx=4,dy=5,dz=-6] — Select all entities whose hitbox intersects with the block region 1~5, 2~7, -3~3.
    • (or, the numerically speaking, a cuboid from 1.0 2.0 -3.0 to 6.0 8.0 4.0).
    • (or, mathematically speaking, the region that is { (x,y,z)∈R³ | x∈[1.0,6.0], y∈[2.0,8.0], z∈[-3.0,4.0] }), or <math>[1, 6] \times [2, 8] \times [-3, 4] \subset \mathbb R^3</math>
It is possible to combine selection by distance and selection by volume, in which case the command select targets only within the overlap of both regions (within a certain radius of the volume's initial point and not outside the defined volume) — but note that distance selection checks that the point at an entity's feet intersects with some sphere, wheras volume selection checks that the entity's hitbox overlaps with some region.

Selecting targets by scores

[scores={<objective>=<value>,...}] — Filter target selection based on their scores in the specified objectives. All tested objectives are in a single object, separated by commas. Each objective and score value pair is separated by an equals sign. The score values support integer ranges. Cannot duplicate this argument.
  • @e[scores={myscore=10}] — Select all entities with a score in objective myscore of exactly ten.
  • @e[scores={myscore=10..12}] — Select all entities with a score in objective myscore of between ten and 12 (inclusive).
  • @e[scores={myscore=5..}] — Select all entities with a score in objective myscore of five or greater.
  • @e[scores={myscore=..15}] — Select all entities with a score in objective myscore of 15 or less.
  • @e[scores={foo=10,bar=1..5}] — Select all entities with a score in objective foo of exactly ten, and a score in objective bar of between one and five (inclusive).
in Template:Editions, ! can be used to invert selection.
  • @e[scores={myscore=!10}] — Exclude any entities with a score in objective myscore of exactly ten.
  • @e[scores={myscore=!10..15}] — Exclude any entities with a score in objective myscore of between ten and 15 (inclusive).

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by tag

Filter target selection based on the entity's scoreboard tags. Multiple tag arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
[tag=<string>] — Include only targets with the specified tag.
[tag=!<string>] — Exclude any targets with the specified tag.
[tag=] — Include only targets with exactly zero tags.
[tag=!] — Include only targets that have at least one tag.

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by team

Script error: No such module "Exclusive".

Filter target selection based on teams. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
[team=<teamName>] — Include only targets in the given team.
[team=!<teamName>] — Exclude any targets in the given team.
[team=] — Include only targets not in a team.
[team=!] — Exclude any targets not in a team.

{{#vardefine:params|0 }}Template:Hatnote

Limiting and sorting target selection

Limit the number of selectable targets for a target selector.
When using the variables @p and @r, this argument defaults to one. Applying the limiting argument to them may increase the number of nearest or random targets selected. When applying this argument to @a or @e, this argument returns only a limited number of targets. Cannot duplicate these arguments.
in Template:Editions: [limit=<value>,sort=(nearest|furthest|random|arbitrary)] — Limit the number of targets, and specify selection priority.
  • sort=nearest — Sort by increasing distance. (Default for @p)
  • sort=furthest — Sort by decreasing distance.
  • sort=random — Sort randomly. (Default for @r)
  • sort=arbitrary — Do not sort. This often returns the oldest entities first due to how the game stores entities internally, but no order is guaranteed. (Default for @e, @a)
in Template:Editions: [c=<value>] — Limit the number of targets.
For @p, @a, and @e, [c=<value>] selects only the specified number of targets by increasing distance from the selector's position. When c is negative, it reverses the order of targeting (for example, @p[c=-1] targets the furthest player). Inverse sorting does not work with @r.
Examples in Template:Editions:
  • @a[limit=3,sort=nearest] or @p[limit=3] — Select the nearest three players.
  • @a[limit=4,sort=furthest] — Select the furthest four players.
  • @a[limit=2,sort=random] or @r[limit=2] — Select two players, chosen randomly.
Examples in Template:Editions:
  • @a[c=3] — Select the nearest three players.
  • @a[c=-4] — Select the furthest four players.
  • @r[c=2] — Select two living players, chosen randomly.

Selecting targets by experience level

Filter target selection based on the entity's experience levels. This naturally filters out all non-player targets. Cannot duplicate these arguments.
in Template:Editions: [level=<value>] — Specifies the range of levels. Integer ranges are supported to select a range of values.
in Template:Editions: [l=<value>] and [lm=<value>] — the maximum and minimum level range to search for, respectively.
Examples in Template:Editions:
  • @a[level=10] — Select all players who have exactly ten levels.
  • @a[level=8..16] — Select all players who have between eight and 16 levels (inclusive).
Examples in Template:Editions:
  • @a[lm=10,l=10] — Select all players who have exactly ten levels.
  • @a[lm=8,l=16] — Select all players who have between eight and 16 levels (inclusive).

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by game mode

Filter target selection by game mode. This naturally filters out all non-player targets. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
in Template:Editions:
[gamemode=<gamemodeName>] — Include only players in the given game mode.
[gamemode=!<gamemodeName>] — Exclude any players in the given game mode.
in Template:Editions:
[m=<gamemodeName>] — Include only players in the given game mode.
[m=!<gamemodeName>] — Exclude any players in the given game mode.
Permitted values for <gamemodeName> are spectator, survival, creative, adventure and defaultTemplate:Only. in Template:Editions, the shorthand values s and 0, c and 1, a and 2, and d and 5 may be used for Survival mode, Creative mode, Adventure mode, and Default mode respectively.

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by name

Filter target selection by name. Values are strings, so spaces are allowed only if quotes are applied. This cannot be a JSON text compound. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
[name=<givenName>] — Include only targets with the given name.
[name=!<givenName>] — Exclude any targets with the given name.

Selecting targets by vertical rotation

Filter target selection based on the entity's rotation along the pitch axis, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down). Cannot duplicate these arguments.
in Template:Editions: [x_rotation=<value>] — Specifies the range of x-rotation. Float ranges are supported to select a specific range of angles.
in Template:Editions [rx=<value>] and [rxm=<value>] — Specifies the maximum and minimum x-rotation, respectively.
Examples in Template:Editions:
  • @e[x_rotation=0] — Select all entities that are looking directly at the horizon.
  • @e[x_rotation=30..60] — Select all entities that are looking between 30° and 60° (inclusive) below the horizon.
  • @e[x_rotation=..0] — Select all entities that are looking at or above the horizon.
Examples in Template:Editions:
  • @e[rxm=0,rx=0] — Selects all entities that are looking directly at the horizon.
  • @e[rxm=30,rx=60] — Selects all entities that are looking between 30° and 60° (inclusive) below the horizon.
  • @e[rx=0] — Select all entities that are looking at or above the horizon.

Selecting targets by horizontal rotation

Filter target selection based on the entity's rotation along the yaw axis, measured clockwise in degrees from due south (or the positive Z direction). Values vary from -180 (facing due north) to -90 (facing due east) to 0 (facing due south) to +90 (facing due west) to +180 (facing due north again). Cannot duplicate these arguments.
in Template:Editions: [y_rotation=<value>] — Specifies the range of y-rotation. Float Ranges are supported to select a specific range of angles.
in Template:Editions: [ry=<value>] and [rym=<value>] — Specifies the maximum and minimum y-rotation values, respectively.
Examples in Template:Editions:
  • @e[y_rotation=0] — Select all entities that are facing due south.
  • @e[y_rotation=-90..0] — Select all entities that are facing in the 90° between due east and due south (inclusive).
  • @e[y_rotation=0..180] — Select all entities that are not facing at all east.
Examples in Template:Editions:
  • @e[rym=0,ry=0] — Select all entities that are facing due south.
  • @e[rym=-90,ry=0] — Select all entities that are facing in the 90° between due east and due south (inclusive).
  • @e[rym=0,ry=180] — Select all entities that are not facing at all east.

Selecting targets by type

Filter target selection based on the entity's identifier. The given entity type must be a valid entity ID or entity type tagTemplate:Only used to identify different types of entities internally. The namespace can be left out if the ID is within the
  1. REDIRECT Template:Code

Template:Redr namespace. Entity IDs or tags are case-sensitive. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can. in Template:Editions, using this argument with @a, @p or @r is not allowed.

[type=<entityType>] — Include only targets of the specified entity type or tag.
[type=!<entityType>] — Exclude any targets of the specified entity type or tag.
in Template:Editions, the option type=<entityType> (without ! symbol) can appear only once, and type=!<entityType> cannot appear with it. If type=<entityType> does not exist, then type=!<entityType> may appear multiple times.
Examples:
  • @e[type=creeper] - Include only creepers.
  • @e[type=creeper, type=pig] - Invalid selector.
  • @e[type=creeper, type=!pig] - Invalid selector.
  • @e[type=!creeper, type=!pig] - Exclude all creepers and pigs.

Selecting targets by family

Script error: No such module "Exclusive".

Filter target selection based on the entity's type_family behavior component. Default values used by the vanilla behavior pack include among others more broad terms like mob and inanimate, as well as more specific families like zombie and skeleton, and single-mob families like wandering_trader and creeper. Multiple family arguments are allowed, and all arguments must be fulfilled for an entity to be selected.{{#vardefine:params|0

}}Template:Hatnote

[family=<family>] — Include only targets in the specified type family.
[family=!<family>] — Exclude any targets in the specified type family.
  • @e[family=skeleton] — Select all skeletons, wither skeletons, strays, bogged, parched, and withers.
  • @e[family=mob,family=!monster] — Select all mobs that are not monsters (so for example cows, chickens, pigs, but not zombies or skeletons).
  • @e[family=monster,family=undead] — Select all monsters that are also undead (that includes monsters like zombies and skeletons, but not creepers, spiders or endermen).

Selecting targets by NBT data

Script error: No such module "Exclusive".

Filter target selection based on the entity's NBT data. The NBT data is written in its SNBT format. Duplicate nbt arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
See NBT format for more infomation about this.
Note that this selector argument should be used with care, as accessing NBT data is a heavy process for the CPU.
[nbt=<compoundTag>] — Include only targets with the specified NBT data.
[nbt=!<compoundTag>] — Exclude any targets with the specified NBT data.
  • @a[nbt={OnGround:true}] — Select all players on the ground.
  • @e[type=sheep,nbt={Color:0b}] — Select all sheep that are dyed white.
  • @e[type=item,nbt={Item:{id:"minecraft:slime_ball"}}] — Selects all slime ball item entities.
  • @e[nbt={Tags:[a,b]}] is the same as @e[tag=a,tag=b]. The latter is simpler and reduces CPU load.

Selecting targets by advancements

Script error: No such module "Exclusive".

Filter target selection based on the entity's advancements. This naturally filters out all non-player targets. All advancements are in a single object, with a list of individual advancement IDs between the braces afterward. The values are true or false. For advancements with one criterion, testing for that criterion always gives the same results as testing for the advancement. Cannot duplicate this argument.
[advancements={<resource location>=<bool>}] — Include only players with the specified advancements and values.
[advancements={<resource location>={<criteria>=<bool>}}] — Include only players with the specified advancement's criteria.
  • @a[advancements={story/smelt_iron=true}] — Include only players who have completed the advancement minecraft:story/smelt_iron.
  • @a[advancements={story/form_obsidian=false}] — Include only players who haven't completed the advancement minecraft:story/form_obsidian.
  • @a[advancements={story/follow_ender_eye=true}] is the same as @a[advancements={story/follow_ender_eye={in_stronghold=true}}].
  • @a[advancements={adventure/kill_all_mobs={witch=true}}] — Include only players who have killed a witch, for the advancement minecraft:adventure/kill_all_mobs.

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by predicate

Script error: No such module "Exclusive".

Filter target selection by predicates. The given values must be a valid predicate represented by a resource location. Duplicate predicate arguments are allowed, and all arguments must be fulfilled for an entity to be selected.
[predicate=<resource location>] — Include only targets that match the specified predicate.
[predicate=!<resource location>] — Exclude any targets that match the specified predicate.

Selecting targets by item

Script error: No such module "Exclusive".

Filter target selection based on whether the entity has the specified items. The given values must be enclosed by square brackets or braces. Cannot duplicate this argument, but multiple items can be specified with square brackets.
[hasitem={<argument>=<value>,<argument2>=<value2>,...}] — Include only targets that have the specified items.
[hasitem=[{<argumentA>=<valueA>,...},{<argumentB>=<valueB>,...}]] — Include only targets that have item A and item B, etc.
All acceptable arguments are as follows:
(More information about what this section is looking for should be given as this section is too vauge.)
  • item (required)
    Must be an Minecraft:item ID.
  • data
    Specifies the item data for the item(s). Must be a 32-bit integer number. Values that are invalid for the specified item id default to 0. If not specified, defaults to 0.
    Note that because it defaults to 0, selectors like {item=potion} can target only water bottle, though {item=potion,data=1} can target mundane potion.
    Currently doesn't work on blocks' direct item forms (e.g. dirt, stone). For these items, data is always considered as invalid and defaults back to 0, and aux value of these items in inventory are also always considered as 0. That means you can't target items like coarse dirt, green wool solely.
    For potion and tipped arrow, aux value represents the data value of potion effect, and currently invalid values crash the game.
  • quantity
    Specifies the amount of the items the entity has. Must be an integer range (e.g. 1 - exact match of 1. ..5 - less than or equal to 5. 5.. - more than or equal to 5. 0..5 - between 0 and 5, inclusive.).
    ! can be used to invert selection. For example, {item=apple,quantity=!5} can exclusive entities who have five apples.
    When not specified, defaults to quantity=1... When quantity=0, entities must have 0 the specified item (i.e. do not have the specified item) to be targeted.
  • location and slot
    Specifies the inventory slot to test. See Minecraft:Slot for details.
    Specifying slot without location is invalid.
    slot must be an integer range. (e.g. 1 - exact match of 1. ..5 - less than or equal to 5. 5.. - more than or equal to 5. 0..5 - between 0 and 5, inclusive.)
  • Example using location: @s[hasitem={item=stick,location=slot.weapon.mainhand}]

Selecting targets by permission

Script error: No such module "Exclusive".

[haspermission={<permission>=<state>,...}] — Filter target selection based on the player permissions status. All tested permissions are in a single object, separated by commas. Cannot duplicate this argument.
  • @a[haspermission={camera=enabled}] — Include only players who have the camera permission enabled.
  • @a[haspermission={movement=disabled}] — Include only players who have the movement permission disabled.
  • @a[haspermission={camera=disabled,movement=enabled}] — Include only players who have the camera permission disabled and the movement permission enabled.

{{#vardefine:params|0 }}Template:Hatnote

Selecting targets by property

Script error: No such module "Exclusive".

Filter target selection based on the entity's property. All tested properties are in a single object, separated by commas. Cannot duplicate this argument.
[has_property={<property>=<value>,...}] — Include only targets that have the specified property values.
[has_property={<property>=!<value>,...}] — Exclude only targets that have the specified property values.
[has_property={property=<property>,...}] — Include only targets that have the specified properties.
[has_property={property=!<property>,...}] — Exclude only targets that have the specified properties.
  • @e[type=chicken,has_property={minecraft:climate_variant=!"cold"}] — Selects all chickens that do not have the minecraft:climate_variant property cold.
  • @e[has_property={minecraft:climate_variant="warm"}] — Selects all entities that have the minecraft:climate_variant property warm (it would only apply to cows, chickens, etc.).
  • @e[has_property={minecraft:has_nectar=true}] — Selects all entities that have the minecraft:has_nectar property true (it would only apply to bees).
  • @e[has_property={minecraft:creaking_swaying_ticks=!1..}] — Selects all entities that do not have the minecraft:creaking_swaying_ticks property 1 or higher (it would apply to all entities except creakings that are swaying).
  • @e[has_property={minecraft:climate_variant=!"temperate",property=minecraft:climate_variant}] — Selects all entities that have the minecraft:climate_variant property except those whose value is temperate.
  • @e[has_property={property=minecraft:armadillo_state}] — Selects all entities that have the minecraft:armadillo_state property.
List of entity properties:

Template:Collapse

Player type and single type

Player type

Some command arguments require a player-type selector, while some require an entity-type selector.

Entity type means that there's no additional restrictions. Any valid selector can be used in this command argument.

A player-type selector is a selector that can only select players, including:

  1. REDIRECT Template:Code

Template:Redr with type=player.

  1. REDIRECT Template:Code

Template:Redr (without

  1. REDIRECT Template:Code

Template:Redr argument in Template:Editions).

  1. REDIRECT Template:Code

Template:Redr with type=playerTemplate:Only or without

  1. REDIRECT Template:Code

Template:Redr argument.

in Template:Editions, if a command argument requires a player type selector, but the entered argument is not in player type, the command is unparseable.

in Template:Editions, if a command argument requires a player type selector, but the entered argument is not in player type, the command is parseable but fails.

Single type

Script error: No such module "Exclusive". Some command arguments require a single-type selector, while some require a multiple-type selector.

Multiple type means that there's no additional restrictions. Any valid selector can be used in this command argument.

A single-type selector is a selector that can only select one target, including:

  1. REDIRECT Template:Code

Template:Redr with limit=1.

  1. REDIRECT Template:Code

Template:Redr without

  1. REDIRECT Template:Code

Template:Redr argument.

  1. REDIRECT Template:Code

Template:Redr without

  1. REDIRECT Template:Code

Template:Redr argument or with limit=1.

If a command argument requires a single-type selector, but the entered argument is not in single-type, the command is unparseable.

Interactive editor

Template:Calculator

History

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

Issues

Script error: No such module "Issue list".

See also

References

<references group="">

 </references>

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 es:Comandos fr:Commandes hu:Szerverparancsok it:Comandi ja:ターゲットセレクター ko:명령어 nl:Opdrachten pl:Polecenia pt:Seletores de destino ru:Команды консоли th:คำสั่ง tr:Komutlar uk:Команди консолі zh:目标选择器