Target selectors

Target selectors are used in commands to specified entities. It is possible to "target" one or more entities satisfying certain conditions. To target entities by condition, choose a target selector variable and, optionally, one or more target selector arguments to modify the conditions to be satisfied.

For example, to change the game mode of all players on team Red to creative mode, instead of specifying them by name individually:

Target selector variables
A target selector variable identifies the broad category of targets to select. There are five (or, $$, seven) variables:




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


 * Target selector arguments may be used to specify what category of players to select the nearest player from. For example,  targets the nearest player on team Red even if there are other players closer.


 * The  or  target selector argument can be used to increase the number of nearest players targeted (for example,   or   targets the three nearest players, respectively).

$$,  ignores dead players. When  is negative, it will reverse the order of targeting (for example, @p[c=-1] will target the farthest player).




 * Targets a random player.


 * Target selector arguments may be used to specify what category of players to select a random player (or more) from. For example,  targets a random player from team Red.


 * The  or  target selector argument can be used to increase the number of nearest players targeted (for example,   or   targets the three nearest players, respectively).


 * $$, can use  to target non-player entities via the   selector argument, while $$ cannot. $$ To select a random entity, use   instead.
 * $$,  ignores dead entities.




 * Targets every player (alive or dead) by default unless Target selector arguments are used. For example,  only targets all players on team Red.




 * Targets all alive entities (including players) in loaded chunks. It ignores dead entities.


 * Target selector arguments may be used to specify what category of entities to target from. For example,  only targets cows.




 * Targets the entity (alive or dead) that executed the command. It does not target anything if the command was run by a command block or server console.


 * Target selector arguments may be used to specify whether the executor is actually eligible to be targeted. For example,  targets the executor of the command if the executor was a cow on team Red.




 * Target the player's agent only.


 * Target selector arguments may be used to target the player's agent. For example,  teleports the player's agent only to the specified location.




 * Target all agents. Works only if more than one agent exists.


 * Target selector arguments may be used to target all agents. For example,  removes all agents.

Target selector arguments
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  or , arguments narrow down the targets from the full list to a specific group. When used with  or , the nearest or random player is selected from the group. When used with, 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:



$$, arguments and values are case-sensitive. Spaces are allowed around the brackets, equal signs, and commas, except $$ 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


 * Define a position in the world the selector starts at, for use with the distance argument or the volume arguments. Defining the position alone can be used with a target selector that selects the nearest or farthest entities from those coordinates, but it otherwise has no use, so applying it (and only it) to  still selects all entities in the same dimension. Cannot duplicate any one of these three arguments.
 * The positional components are doubles, allowing for values like, and they are not center-corrected, meaning   is not corrected to.
 * $$, tilde notation is available for selector argument coordinates.
 * $$, tilde notation is available for selector argument coordinates.




 * 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. Cannot duplicate this argument.


 * - Specifies the range of distance. Only unsigned values are allowed.
 * Ranges are supported to select a specific region:
 * — Target all entities exactly ten blocks away.
 * — Target all entities more than eight blocks, but less than 16 blocks away (inclusive).
 * — Target all entities between source and 16 blocks away (inclusive).
 * — Target all entities between source and 16 blocks away (inclusive).


 * - Specifies the maximum range to find entities. Only unsigned values are allowed.
 * - Specifies the minimum range of distance. Only unsigned values are allowed.
 * As such:
 * — Target all entities exactly ten blocks away.
 * — Target all entities from 8 to 16 blocks away.
 * — Target all entities from 8 to 16 blocks away.




 * - Filter target selection based on their x-difference, y-difference, and z-difference from some point, as measured from the closest corner of the entities' hitboxes or by their feet. Cannot duplicate any one of these three arguments.
 * This can be interpreted as creating a rectangular volume defined by an initial position (,,) and diagonal vector (,,), then selecting all entities whose hitboxes are at least partially contained by that volume, or whose feet are within that volume. 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.
 * Note that, ,  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.
 * Examples $$:
 * — Select all entities whose hitbox collides with the block region (1~5, 2~7, 3~9) (or, mathematically speaking, the region that is {(x,y,z)∈R3|x∈[1.0,5.0),y∈[2.0,7.0),z∈[3.0,9.0)}).
 * — Select all entities whose hitbox contains the point (1,2,3).
 * Examples $$:
 * — Select all entities whose feet are within the block region (1~5, 2~7, 3~9).
 * — Select all entities whose feet contains the point (1, 2, 3).
 * 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/I of the volume's initial point and not outside the defined volume).




 * - Filter target selection based on their scores in the specified objectives. Cannot duplicate this argument.
 * All tested objectives are in a single tag, with a list of individual score selectors between braces afterward. The selectors inside the braces support ranges.
 * — Select all entities with a score in objective myscore of exactly ten.
 * — Select all entities with a score in objective myscore of between ten and 12 (inclusive).
 * — Select all entities with a score in objective myscore of five or greater.
 * — Select all entities with a score in objective myscore of 15 or less.
 * — Select all entities with a score in objective foo of exactly ten, and a score in objective bar of between one and five (inclusive).
 * $$,  can be used to invert selection.
 * — Select all entities with a score in objective myscore other than ten.
 * — Select all entities with a score in objective myscore of 0 to 10 (inclusive), and 15 or greater.


 * Cannot duplicate this argument.
 * - Filter target selection to those who are on a given team.
 * — Filter to those who are not on a given team.
 * — Filter to those who are teamless.
 * — Filter to those who have some team.
 * — Filter to those who have some team.


 * Limiting and sorting target selection
 * Cannot duplicate these arguments.


 * :  - Selects only the specified number of targets.
 * :  - Selects only the specified number of targets. Usually in order of distance from the command executor.


 * When using the variables  and , this argument defaults to one. Applying the limiting  argument to them may artificially increase the number of nearest or random targets selected. When applying this argument to   or  , this argument returns only a limited number of targets.


 * $$:  - Limit the number of targets, and specify selection priority.
 * — Sort by increasing distance. (Default for )
 * — Sort by decreasing distance.
 * — Sort randomly. (Default for )
 * — Do not sort. (Default for,  )


 * For,  , and  ,   selects only the specified number of targets in order of distance from the command executor.
 * When  is negative, it will reverse the order of targeting (for example, @p[c=-1] will target the farthest player).
 * When  is negative, it will reverse the order of targeting (for example, @p[c=-1] will target the farthest player).


 * Examples $$:
 * or  — Select the nearest three players.
 * — Select the furthest four players.
 * or  — Select two players, chosen randomly.
 * Examples $$:
 * — Select the nearest three players.
 * — Select the furthest four players.
 * — Select two living players, chosen randomly.




 * Filter target selection based on their experience levels. This naturally filters out all non-player targets.


 * Cannot duplicate this argument. This selector supports ranges:
 * — Select all players who have exactly ten levels.
 * — Select all players who have between eight and 16 levels (inclusive).
 * — Select all players who have between eight and 16 levels (inclusive).


 * - the maximum level to search for.
 * - the minimum level to search for.
 * Cannot duplicate any one of these two arguments. As such:
 * — Select all players who have exactly ten levels.
 * — Select all players who have between eight and 16 levels (inclusive).
 * — Select all players who have between eight and 16 levels (inclusive).


 * This naturally filters out all non-player targets. Cannot duplicate this argument.
 * — Filter target selection to those who are in the specified game mode.
 * — Filter target selection to those who are not in the specified game mode.
 * — Filter target selection to those who are in the specified game mode.
 * — Filter target selection to those who are not in the specified game mode.
 * — Filter target selection to those who are in the specified game mode.
 * — Filter target selection to those who are not in the specified game mode.
 * — Filter target selection to those who are not in the specified game mode.


 * Permitted values for  are,  ,  , and  . $$, the shorthand values   and  ,   and  , and   and   may be used for Adventure mode, Creative mode, and Survival mode respectively.


 * Examples $$:
 * — Select all players who are in Survival mode.
 * — Select all players who are not in Spectator mode.
 * Examples $$:
 * or  or   — Select all players who are in Survival mode.
 * or  or   — Select all players who are not in Creative mode.


 * Cannot duplicate this argument.
 * — Filter target selection to all those with a given name.
 * — Filter target selection to all those without a given name.
 * This is a string, so spaces are allowed only if quotes are applied. This cannot be a JSON text compound.
 * - Select all entities that are not named "Steve".
 * - Select all entities that are not named "Steve".


 * Filter target selection based on their pitch, or more specifically their declination from the horizon, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down). Cannot duplicate this argument.
 * Filter target selection based on their pitch, or more specifically their declination from the horizon, measured in degrees. Values range from -90 (straight up) to 0 (at the horizon) to +90 (straight down). Cannot duplicate this argument.


 * This argument supports ranges:
 * — Select all entities that are looking directly at the horizon.
 * — Select all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
 * — Select all entities that are looking 45&deg; or more below the horizon.
 * — Select all entities that are looking at or above the horizon.
 * — Select all entities that are looking at or above the horizon.


 * - the maximum x-rotation value to search for.
 * - the minimum x-rotation value to search for.
 * As such:
 * — Selects all entities that are looking directly at the horizon.
 * — Selects all entities that are looking between 30&deg; and 60&deg; (inclusive) below the horizon.
 * — Select all entities that are looking 45&deg; or more below the horizon.
 * — Select all entities that are looking at or above the horizon.
 * — Select all entities that are looking at or above the horizon.


 * Filter target selection based on their rotation in the horizontal XZ-plane, 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 this argument.
 * Filter target selection based on their rotation in the horizontal XZ-plane, 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 this argument.


 * This argument supports ranges, and the maximum can reach values over 180. Some examples:
 * — Select all entities that are facing due south.
 * — Select all entities that are facing 45&deg; west of south.
 * — Select all entities that are facing in the 90&deg; between due north and due east (inclusive).
 * — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
 * — Select all entities that are facing between due east and due west (inclusive), through south.
 * — Select all entities that are not facing at all east.
 * — Select all entities that are not facing at all east.


 * - the maximum y-rotation value to search for.
 * - the minimum y-rotation value to search for.
 * As such:
 * — Select all entities that are facing due south.
 * — Select all entities that are facing 45&deg; west of south.
 * — Select all entities that are facing in the 90&deg; between due east and due south (inclusive).
 * — Select all entities that are not facing at all east.
 * — Select all entities that are not facing at all east.




 * — Filter target selection to those of a specific entity type.
 * — Filter target selection to those not of a specific entity type.
 * The given entity type must be a valid entity ID or entity type tag used to identify different types of entities internally. The namespace can be left out if the ID is within the  namespace. (For example,   for creepers,   for regular minecarts,   for primed TNT, etc.) Entity IDs or tags are case-sensitive.
 * $$, when using the  parameter, this argument defaults to the type  . Defining a type for this parameter can filter the random selection to other entities.
 * Examples:
 * — Select all skeletons.
 * — Select all entities except chickens and cows.
 * — Select all skeletons, wither skeletons, and strays.


 * — Filter target selection to those of a specific entity family.
 * — Filter target selection to those not of a specific entity family.
 * Multiple family arguments are allowed. The given entity family can be any string. It does not include a namespace. These entity families are defined in an entities type_family behavior component. Default values used by the vanilla behavior pack include among others more broad terms like,  ,   and   as well as more specific, smaller families like   and   and single-mob families like  ,   and  . A single entity can be part of multiple families.
 * — Select all skeletons, wither skeletons and strays.
 * — Select all mobs that are not also monsters (so for example cows, chickens, pigs, but not zombies or skeletons).
 * — Select all monsters that are also undead (that includes monsters like zombies and skeletons, but not creepers or endermen).
 * — Select all monsters that are also undead (that includes monsters like zombies and skeletons, but not creepers or endermen).




 * — Filter target selection to those that have at least one tag of the given name.
 * — Filter to those that have no tags of the given name.
 * — Filter to those that have exactly zero tags.
 * — Filter to those that have at least one tag.
 * Multiple tag arguments are allowed. All argument specifications must be fulfilled for an entity to be selected.
 * — Select all entities that have tags a and b, but not tag c.
 * — Select one random player who has tag a.


 * Selecting targets by NBT


 * — Select all targets that have the specified NBT. The NBT is written in its command definition.
 * — Select all targets that does not have the specified NBT.
 * For example:
 * — Select all players on the ground.
 * — Select all sheep that are dyed white.
 * — Selects all slime ball item entities.
 * is the same as . The latter is simpler and reduces CPU load.
 * Note: When matching the string form of namespaced IDs within a tag, the namespace cannot be omitted.
 * Hence  cannot find any item entities as the  field always contains a namespaced ID-converted string.




 * — Select all targets that match the specified advancement and value.
 * — Select all targets that match the specified advancement and value.
 * The argument name is the advancement ID (namespace can be left out when namespaced ). The value is true or false.
 * For advancements with one criterion, testing for that criterion always gives the same results as testing for the advancement.
 * — Selects players who have achieved the advancement minecraft:story/form_obsidian.
 * — Selects players who haven't achieved the advancement minecraft:story/form_obsidian.
 * — Selects players who had armored with iron helmet. The selected players needn't be wearing iron helmet when selected, and needn't have achieved the advancement minecraft:story/obtain_armor.
 * is the same as.


 * Selecting targets by predicate


 * — Select all targets that match the specified predicate.
 * — Select all targets that fail to match the specified predicate.


 * Examples:
 * — Selects players who match the example:test_predicate predicate.
 * — Selects entities who do not match the minecraft-wiki:smart_entity predicate.