How to Implement Special Arguments in Minecraft Commands
Sometimes, commands require you to know specific information about the Minecraft world. For example, the teleport command doesn’t work unless you enter the name of a player who’s currently online — this can be quite impractical in a server where several players join and leave. Fortunately, there are a few versatile substitutes for common parameters that you can use to make your commands always work.
Examining relative positions
Many commands require you to enter coordinates as parameters, which can be cumbersome. For example, if you want to target a particular location, you have to press F3, record your coordinates, find the difference between your coordinates and those of the target location, and calculate the target location.
Relative positions are often easy to calculate, and they’re useful for writing generalized commands. Essentially, if you precede a coordinate with a tilde (~), the coordinate is relative to the player or command block running the command.
For example, if you enter the coordinates ~0 ~-1 ~0, the command interprets this as the space just below the player or command block. You can even use a single tilde in place of ~0, so you can, for example, use the command fill ~ ~ ~ ~ ~1 ~ gold_block to place gold blocks on both your position and the position just above you.
Similarly, tp Isometrus ~5 ~3 ~ teleports the player Isometrus five blocks to the east and three blocks up from his original position.
Much like relative positions, selectors are used to write general and versatile commands with many applications. They allow you to target players without knowing their usernames, target several players, and even target entities of all sorts (basically any nonblock object in the world, including creepers, minecarts, and fireballs).
If you right-click a command block, the screen that appears contains the following information about using selectors:
Use "@p" to target nearest player Use "@r" to target random player Use "@a" to target all players Use "@e" to target all entities
You can use these selectors in place of any parameter that requests a target, such as a player. For example, if you use the command tp @r 0 64 0, a random player is teleported to the coordinates (0, 64, 0). However, if you type tp @e 0 64 0, every entity in the world is teleported there.
You can also add modifiers to a selector, making it target only certain entities. For example, @a[r=20] targets all players within 20 blocks, and @e[type=Zombie,c=3] targets three zombies. Every modifier takes this form:
[<argument1>=<value1>,<argument2>=<value2>,…,<last argument>=<last value>]
If you apply this modifier, the selector targets every entity for which every argument is satisfied by the value given. To explain this, check out the list of arguments you can apply, and which entities they accept.
|c||Limits the number of entities to target. For example, c=4 finds the first four entities, and c=-2 finds the last two.|
|l||Targets players with a certain maximum level.|
|lm||Targets players with a certain minimum level.|
|m||Targets players in a certain game mode. 0 is Survival, 1 is
Creative, 2 is Adventure, and 3 is Spectator.
|r||Targets entities within a certain range.|
|rxm, rx||Targets entities whose rotation about the x-axis is between the
values given (clockwise from rxm,
counterclockwise from rx).
|rym, ry||Targets entities whose rotation about the y-axis is between the
values given (clockwise from rym and
counterclockwise from ry).
|score_<name>||Targets players whose score in the objective is at most the
given value. (<name> is an
objective in the scoreboard).
|Score_<name>_min||Targets players whose score in the objective is at least the
given value. (<name> is an
objective in the scoreboard.
|team||Targets all players on the team whose team name matches the
|name||Targets entities with a certain name. Entities with names
include players (with their usernames) and mobs that were named
(for example, with the Name Tag item).
|type||Targets entities with a certain type, such as Player, Chicken, or
PigZombie. You can find the different
entity types by using the autocompletion feature on the summon command.
|x, y, z||Tests for entities at the target coordinates. Modifiers such as
r and dx are
centered at these coordinates.
|Tests for entities at most a certain distance away in the x, y,
and z directions, respectively (thus searching for entities in a