/

Minecraft target selectors

A target selector is the @e[type=zombie,distance=..10] part of a command — it decides what the command applies to. Build one below and copy it into any command, or read the full argument reference underneath.

All entities
@e

The six selector variables

@pNearest player
@aAll players
@rRandom player
@sThe executing entity
@eAll entities
@nNearest entity1.20.5+

@s is the odd one out: it always means the entity currently running the command, so narrowing it by distance, limit or sort does nothing. Everything else can be filtered with the arguments below.

Every selector argument

type

Only this kind of entity

Restricts the match to one entity type. Prefix with ! to exclude instead, and repeat it to exclude several. Only one positive type is allowed, since nothing can be two types at once. An item tag such as #minecraft:skeletons matches a whole group.

@e[type=zombie]

tag

Has a scoreboard tag

Matches entities carrying a scoreboard tag added with /tag. Tags need no setup and survive reloads, which makes them the usual way to mark "the one I mean" across ticks. Repeat the argument to require several, and prefix with ! to exclude.

@e[tag=boss,tag=!dead]

name

Exact name match

Matches the entity name exactly — a player name, or a mob's custom name. Quote it if it contains spaces. It is an exact comparison, not a search.

@e[name="Frost Guardian"]

distance

Range from the command position, e.g. ..10

Distance in blocks from wherever the command is running. Ranges are open-ended on either side: ..10 is within 10 blocks, 5.. is at least 5, and 3..7 is between the two. Measured in three dimensions, so height counts.

@e[distance=..10]

limit

Match at most this many

Caps how many entities can match. Pair it with sort to decide which ones survive the cap — on its own, limit takes an arbitrary subset. @p and @r already imply limit=1.

@e[limit=1,sort=nearest]

sort

Which ones the limit keeps

Orders matches before limit trims them. nearest and furthest are by distance, random shuffles, and arbitrary skips sorting entirely, which is the fastest when order does not matter.

@e[sort=furthest,limit=3]

scores

Scoreboard value ranges

Matches on scoreboard objectives, using the same open-ended ranges as distance. Several objectives inside one set of braces must all match. An entity with no score at all for an objective never matches.

@a[scores={kills=10..,deaths=..2}]

team

Member of a team

Matches members of a team created with /team. Use team= with nothing after it to match entities on no team, and !team= to match everyone who is on some team.

@a[team=red]

gamemode

Players in this modeplayers only

Players only. Prefix with ! to exclude a mode — @a[gamemode=!spectator] is a common way to skip spectators.

@a[gamemode=survival]

level

Experience level rangeplayers only

Players only. Matches experience levels, not points, and takes the same open-ended ranges as distance.

@a[level=30..]

nbt

Matches this NBT

Matches entities whose NBT contains everything you list — a subset test, not an exact comparison, so you only write the parts you care about. From 1.20.5 item data lives under components rather than tag.

@a[nbt={SelectedItem:{id:"minecraft:diamond_sword"}}]

predicate

A data pack predicate passes

Runs a predicate from a data pack against each candidate. This is the escape hatch for conditions selectors cannot express on their own, such as weather, biome or item durability.

@a[predicate=my_pack:is_holding_sword]

x_rotation / y_rotation

Facing within a yaw or pitch range

Matches which way an entity is looking. y_rotation is yaw, where 0 is south and values run -180 to 180; x_rotation is pitch, -90 straight up to 90 straight down.

@a[y_rotation=-45..45]

dx / dy / dz

Inside a box of this size

Matches everything inside a box that starts at the command position and extends by dx, dy and dz blocks. It is a volume, not a radius, and any axis you leave out is treated as 0.

@e[dx=10,dy=5,dz=10]

x / y / z

Measure from a fixed point instead

Moves the point that distance and the dx/dy/dz volume measure from, so a selector can be anchored somewhere other than where the command runs.

@e[x=0,y=64,z=0,distance=..20]

advancements

Has or lacks an advancementplayers only

Players only. Matches on whether an advancement has been earned, and can test individual criteria within one advancement rather than the whole thing.

@a[advancements={minecraft:story/mine_stone=true}]

Selectors worth memorising

  • Every player except spectators
    @a[gamemode=!spectator]
    The usual way to skip spectators in a minigame
  • Nearest zombie within 10 blocks
    @e[type=zombie,distance=..10,limit=1,sort=nearest]
    From 1.20.5 this is just @n[type=zombie,distance=..10]
  • Dropped items only
    @e[type=item]
    Item entities on the ground, not items in inventories
  • Everything but players
    @e[type=!player]
    Still includes armour stands, item frames, paintings and boats
  • Players with a score of 10 or more
    @a[scores={kills=10..}]
    Open-ended range: 10 and upwards
  • Entities tagged by a previous command
    @e[tag=boss]
    Tags need no setup and survive a reload
  • Players in a 10×5×10 box
    @a[dx=10,dy=5,dz=10]
    A volume from the command position, not a radius
  • A random player
    @r
    Equivalent to @a[limit=1,sort=random]

Common questions about target selectors

What is the difference between @a and @e?

@a matches players only. @e matches every entity, which includes mobs, dropped items, armour stands, item frames, paintings, boats and minecarts. This is why /kill @e is so destructive and /kill @e[type=!player] is still not safe — it removes item frames and armour stands too.

How do I select the nearest mob rather than the nearest player?

@p is players only, so use @e[type=zombie,limit=1,sort=nearest]. From 1.20.5 there is a shorthand: @n means the nearest entity of any type, so @n[type=zombie] does the same thing.

How do I select players within a radius?

Use distance with an open-ended range. @a[distance=..10] matches players within 10 blocks, @a[distance=5..] matches those at least 5 blocks away, and @a[distance=3..7] matches the band between them. Distance is measured in three dimensions, so a player 10 blocks directly above you counts as 10 away.

Why does my selector match nothing?

Usually the position it measures from. distance and dx/dy/dz are relative to wherever the command runs, which for a command block is the block itself, not the player. Wrapping the command in /execute as @a at @s run … makes each player the reference point.

Can I use two type= arguments at once?

Only if all but one are negated. Nothing can be two entity types simultaneously, so @e[type=zombie,type=skeleton] matches nothing, while @e[type=!player,type=!item] is fine. To match several types, use an entity type tag such as #minecraft:skeletons.

What is the difference between distance and dx/dy/dz?

distance is a sphere measured from a point. dx, dy and dz define a box that starts at the command position and extends by that many blocks in each direction. The box is not centred on the position — it grows from it.

Does the order of selector arguments matter?

Not for the result, but it can matter for performance. The game applies arguments in the order written, so putting the most restrictive one first — usually type or a tag — means fewer entities get tested by the later, more expensive checks such as nbt or predicate.

How do I select a player whose name has a space in it?

Quote it: @a[name="Frost Guardian"]. Java Edition player names cannot contain spaces, but custom entity names can, so this comes up with named mobs and armour stands.

Every generator here embeds this same builder wherever a command takes a target — try it on /kill, /effect or /execute.