Target Selector Generator — Build @e, @a, @p Selectors With Filters (Minecraft)
Run these from an operator’s chat, a command block, or a function file. Stopwatch and Fetchprofile are newer commands — check availability on your Minecraft version.
How to Use the Target Selector Generator
- Pick a base selector:
@p(nearest player),@a(all players),@r(random player),@e(all entities), or@s(the command’s own executor). - Optionally narrow it down with Type (e.g.
minecraft:zombie), Distance (e.g...5for within 5 blocks), and Limit (max number of matches). - Optionally add Sort (nearest/furthest/random/arbitrary), Gamemode, and Team filters.
- Optionally add a Tag, an exact Name, and an experience Level range.
- Optionally constrain X Rotation (pitch) and Y Rotation (yaw) ranges to filter by facing direction.
- Copy the generated selector string and drop it into any command argument that accepts a target –
/kill,/tp,/execute as, and dozens more.
Command Syntax Reference
@e[type=<id>,distance=<range>,limit=<n>,sort=<nearest|furthest|random|arbitrary>,gamemode=<mode>,team=<team>,tag=<tag>,name=<name>,level=<range>,x_rotation=<range>,y_rotation=<range>]
A target selector is a variable that resolves to one or more entities at the moment a command runs, instead of naming a specific entity directly. The five base selectors each start from a different pool: @p the single nearest player, @a every player, @r one random player, @e every entity (including non-players), and @s whoever or whatever executed the command. Square-bracket arguments narrow that pool: distance=..5 means “5 blocks or closer” (a two-dot range), limit=1 caps how many matches come back, sort=nearest picks which matches win when the limit cuts the pool down, and gamemode/team/tag/name/level filter by exactly those attributes. x_rotation and y_rotation filter by where an entity is looking (pitch and yaw), which is a less common but genuinely useful way to require a player to be looking in a certain direction before a command fires.
Frequently Asked Questions
What does a range like ..5 or 1..5 actually mean?
A range uses two dots between a minimum and maximum. Leaving the start blank (..5) means “5 or less,” leaving the end blank (1..) means “1 or more,” and giving both (1..5) bounds it on both sides. This same range syntax works for distance, level, and rotation arguments.
Why would I use @e[type=!minecraft:player] instead of just picking a mob type?
Negation with ! in front of a value excludes it instead of requiring it – type=!minecraft:player matches every entity that is not a player, which is a common way to affect “everything except players” without listing every mob type individually. (Type this directly into the Type field with the exclamation mark.)
What’s the point of sort combined with limit?
Limit alone just caps the count, but without a defined order the specific matches it keeps are effectively arbitrary. Pairing limit=1 with sort=nearest deterministically picks the single closest match, which is the standard pattern for “target whichever zombie is closest to me.”
Can I combine multiple filters like type, distance, and gamemode at once?
Yes – every filter you fill in gets joined with commas inside the same bracket, so a selector like @a[distance=..10,gamemode=survival] combining several conditions at once is completely normal and is exactly how complex selectors are built in practice.
Related Tools
- Fetchprofile Command Generator – look up a full profile for a selector’s matched entity.
- Trigger Command Generator – a selector-free command scoped to the executor only.
- Kill Command Generator – plug a target selector straight into /kill.