Target selectors

Target selectors are used in 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.

For example, to change the game mode of all players to Creative mode, instead of specifying each of them by name individually:

Target selector variables
A target selector variable identifies the broad category of targets to select. There are five (six $$, 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.


 * $$,  only targets players who are alive.




 * Targets a random player.


 * can use  to target non-player entities via the   selector argument; $$, to select a random entity, use   instead.
 * $$,  can only target entities who are alive.




 * Targets every player, alive or not.




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




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




 * Target the player's agent only.




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




 * Targets the player who interacts with a button in a JSON NPC dialogue.

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, the volume arguments, or the limit argument. Using these arguments alone will not restrict the entities found, and will only affect the sorting of targets. 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.
 * $$, these arguments limit the search of entities to the current dimension.




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


 * $$:  — Specifies the range of distance. Float ranges are supported to select a specific region. Only unsigned values are allowed.


 * $$:  and   — Specifies the maximum and minimum range to find entities, respectively. Only unsigned values are allowed.


 * Examples $$:
 * — Target all entities exactly ten blocks away.
 * — Target all entities more than eight blocks, but less than 16 blocks away (inclusive).


 * Examples $$:
 * — Target all entities exactly ten 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 by 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.
 * Additionally, when any volume argument is present, the rest are assumed to equal zero unless otherwise defined.


 * 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 of the volume's initial point and not outside the defined volume).




 * — Filter target selection based on their scores in the specified objectives. All tested objectives are in a single object, with a list of individual score arguments between braces afterward. The values inside the braces support integer ranges. Cannot duplicate this argument.
 * — 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.
 * — Exclude any entities with a score in objective myscore of exactly ten.
 * — Exclude any entities with a score in objective myscore of between ten and 15 (inclusive).




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


 * — Include only targets with the specified tag.
 * — Exclude any targets with the specified tag.
 * — Include only targets with exactly zero tags.
 * — Exclude any targets that have at least one tag.




 * Filter target selection based on teams. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.
 * — Include only targets in the given team.
 * — Exclude any targets in the given team.
 * — Include only targets not in a team.
 * — Exclude any targets not in a team.


 * Limiting and sorting target selection


 * Limit the number of selectable targets for a target selector.
 * When using the variables  and , 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   or  , this argument returns only a limited number of targets. Cannot duplicate these arguments.


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


 * $$:  — Limit the number of targets.
 * For,  , and  ,   selects only the specified number of targets by increasing distance from the selector's position. When   is negative, it will reverse the order of targeting (for example,   will target the furthest player). Inverse sorting does not work with.


 * 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 the entity's experience levels. This naturally filters out all non-player targets. Cannot duplicate these arguments.


 * $$:  — Specifies the range of levels. Integer ranges are supported to select a range of values.


 * $$:  and   — the maximum and minimum level range to search for, respectively.


 * Examples $$:
 * — Select all players who have exactly ten levels.
 * — Select all players who have between eight and 16 levels (inclusive).


 * Examples $$:
 * — Select all players who have exactly ten levels.
 * — Select all players who have between eight and 16 levels (inclusive).


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


 * — Include only players in the given game mode.
 * — Exclude any players in the given game mode.
 * — Exclude any players in the given game mode.


 * — Include only players in the given game mode.
 * — Exclude any players in the given game mode.
 * — Exclude any players in the given game mode.


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




 * 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.
 * — Include only targets with the given name.
 * — Exclude any targets with the given name.




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


 * $$:  — Specifies the range of x-rotation. Float ranges are supported to select a specific range of angles.


 * $$  and   — Specifies the maximum and minimum x-rotation, respectively.


 * Examples $$:
 * — 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 at or above the horizon.


 * Examples $$:
 * — 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 at or above the horizon.




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


 * $$:  — Specifies the range of y-rotation. Float Ranges are supported to select a specific range of angles.


 * $$:  and   — Specifies the maximum and minimum y-rotation values, respectively.


 * Examples $$:
 * — Select all entities that are facing due 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.


 * Examples $$:
 * — Select all entities that are facing due 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.




 * Filter target selection based on the entity's identifier. 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. Entity IDs or tags are case-sensitive. Arguments testing for equality cannot be duplicated, while arguments testing for inequality can.


 * — Include only targets of the specified entity type or tag.
 * — Exclude any targets of the specified entity type or tag.




 * 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  and , as well as more specific families like   and  , and single-mob families like   and  . Multiple family arguments are allowed, and all arguments must be fulfilled for an entity to be selected.


 * — Include only targets in the specified type family.
 * — Exclude any targets in the specified type family.


 * — 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).


 * Selecting targets by NBT data


 * Filter target selection based on the entity's NBT data. The NBT data is written in its SNBT format. Multiple 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.
 * — Include only targets with the specified NBT data.
 * — Exclude any targets with the specified NBT data.


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




 * 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.
 * — Include only players with the specified advancements and values.
 * — Include only players with the specified advancement's criteria.


 * — Include only players who have completed the advancement minecraft:story/smelt_iron.
 * — Include only players who haven't completed the advancement minecraft:story/form_obsidian.
 * is the same as.




 * Filter target selection by predicates. The given values must be a valid predicate represented by a namespaced ID. Multiple predicate arguments are allowed, and all arguments must be fulfilled for an entity to be selected.


 * — Include only targets that match the specified predicate.
 * — Exclude any targets that match the specified predicate.