This Minecraft tutorial explains all about target selectors and how to use them in game commands and cheats.
What is a Target Selector?
A target selector is used to target players or entities in your game commands. There are 5 target selectors that you can choose from:
Target Selector | Description |
---|---|
@p | Targets the nearest player |
@r | Targets a random player |
@a | Targets all players |
@e | Targets all entities (See list of entities in Minecraft) |
@s | Targets the entity that is executing the command (referred to as "yourself") |
Let's explore what each of these target selectors do.
Target Selectors
@p
(Nearest Player)
The @p target selector is used to target the nearest player in the game. The nearest player will always be the player closest to the location where the command is run.
If a command block has executed the command, the nearest player to the command block will be targeted. If you run a command from the Chat window, the player running the command will be the nearest player.
For example, you can use the @p selector with the /give command to give the nearest player 5 gold blocks:
/give @p gold_block 5
@r
(Random Player)
The @r target selector is used to target a random player in the game.
For example, you can use the @r selector with the /give command to give a random player 15 emeralds:
/give @r emerald 15
@a
(All Players)
The @a target selector is used to target all players in the game.
For example, you can use the @a selector with the /give command to give all players 2 emeralds:
/give @a emerald 2
@e
(All Entities)
The @e target selector is used to target all entities in the game. This includes both players and mobs in the world.
For example, you can use the @e selector with the /kill command to kill all enderman:
/kill @e[type=enderman]
Notice that in this last example, we have used [type=enderman]
to target only enderman. This value is called a target selector argument and allows us to filter the target.
Let's explore target selector arguments further.
@s
(Entity executing the command)
The @s target selector is used to target the entity that is executing the command. This is often referred to as "yourself" in the Minecraft help.
For example, you can use the @s selector with the /give command to give the player who is running the command 64 tnt:
/give @s tnt 64
Target Selector Arguments
Target selector arguments can be used to reduce the number of players or entities being targeted and the available options are different between Java Edition and Bedrock Edition.
- Java
- Bedrock
Java Edition: Target Selector Arguments
In Java Edition, here are some of the more popular target selector arguments that you can use:
Target Selector Argument | Description |
---|---|
advancements | Advancement earned by entity. |
distance | Distance to entity. |
dx | Entities between x and x + dx. |
dy | Entities between y and y + dy. |
dz | Entities between z and z + dz. |
gamemode | Players with gamemode. It can be one of the following values: adventure, creative, spectator, survival, !adventure, !creative, !spectator, !survival |
level | Experience level. It must be an integer value that is 0 or greater. |
limit | Maximum number of entities to target. It must be an integer value that is 1 or greater. |
name | Entity name. |
nbt | NBT tag. |
scores | Score. |
sort | Sort the entities. It must be one of the following values: arbitrary, furthest, nearest, random |
tag | Scoreboard tag. |
team | Entities on team. |
type | Entity type (target must be the specified entity type - see list of entity values). |
x | Entity's x-coordinate position. |
y | Entity's y-coordinate position. |
z | Entity's z-coordinate position. |
x_rotation | Entity's x rotation (vertical rotation). |
y_rotation | Entity's y rotation (horizontal rotation). |
A target selector argument is case-sensitive and always surrounded in [ ] such as [type=cow]
. If there is more than one target selector argument used in a command, the arguments are separated by a comma such as [type=cow,limit=5]
.
Java Edition: Target Selector Argument Examples
Here are some examples of how to use target selector arguments in Java Edition.
To kill all cows:
/kill @e[type=cow]
To kill 5 cows:
/kill @e[type=cow,limit=5]
To give the 3 nearest players 64 emeralds:
/give @a[sort=nearest,limit=3] emerald 64
Java Edition: Common Mistakes with Target Selector Arguments
Here are some common mistakes made with dealing with target selector arguments in Java Edition.
1. Spaces between Target Selector and Argument
Do not put spaces between the target selector and the target selector arguments. If you do, the target selector argument will be ignored.
INCORRECT:
@e [type=cow]
CORRECT:
@e[type=cow]
2. Capitalizing the first letter of an Argument
Target selectors are case-sensitive and are generally all lowercase. Do not capitalize the first letter of an argument. If you misspell a target selector argument (and accidentally uppercase the first letter of the argument), the target selector argument will be ignored.
INCORRECT:
@e[Type=cow]
CORRECT:
@e[type=cow]
Bedrock Edition: Target Selector Arguments
In Bedrock Edition, here are some of the more popular target selector arguments that you can use:
Target Selector Argument | Description |
---|---|
c | Count (number of targets to select) |
dx | Entities between x and x + dx |
dy | Entities between y and y + dy |
dz | Entities between z and z + dz |
l | Maximum experience level |
lm | Minimum experience level |
m | Game mode (target must be playing in the specified game mode) |
name | Entity name |
r | Maximum radius (target must be within the specified number of blocks) |
rm | Minimum radius (target must be more that the specified number of blocks away) |
rx | Maximum vertical rotation |
rxm | Minimum vertical rotation |
ry | Maximum horizontal rotation |
rym | Minimum horizontal rotation |
tag | Scoreboard tag |
type | Entity type (target must be the specified entity type - see list of entity values) |
x | Entity's x-coordinate position |
y | Entity's y-coordinate position |
z | Entity's z-coordinate position |
A target selector argument is case-sensitive and always surrounded in [ ] such as [type=cow]
. If there is more than one target selector argument used in a command, the arguments are separated by a comma such as [type=cow,r=50]
.
Bedrock Edition: Target Selector Argument Examples
Here are some examples of how to use target selector arguments in Bedrock Edition.
To kill all cows:
/kill @e[type=cow]
To give all players within a 50 block radius 6 emeralds:
/give @a[r=50] emerald 6 0
To give the 3 closest players 17 diamonds:
/give @p[c=3] diamond 17 0
Congratulations, you have learned about target selectors in Minecraft. Now, try a game command using a target selector.