User:Aeldrion/CommandGuide/Coordinates and selectors

In this section, we're going to learn about two major components of the command system: coordinates and target selectors. Coordinates are used in many commands to specify a position whereas target selectors specify which mobs or players are affected by a specific command.

Target selectors
In the previous section, we've been using  and usernames in the  command. is called a target selector: it is an argument that selects specific mobs or players - in this example, the player running the command in the chat. There are many more target selectors: one that selects a random player, one that selects all players, one that selects every mob in the world... In fact, target selectors are not limited to mobs and players, but can select all types of entities. In Minecraft, an entity is pretty much any object that isn't a block; this includes players, mobs, but also projectiles (arrows, eggs, snowballs...), armor stands, item frames, paintings, dropped items and many more.

A target selector can be composed of two things: a variable and an optional list of target selector arguments. There are five variables (@a, @e, @p, @r, @s): @a selects all players, @e selects all entities, @p selects all players, @r selects a random player and @s selects the player or entity that is executing the command. Selector arguments are filters that will remove entities to the list of selected entities. For example,  will only select entities that match the arguments used between the square brackets.

Target selector arguments
To illustrate what these target selectors do, we will be using the command. This command has the property of modifying any target selector it finds with the names of all selected entities, split with a comma. For example, running  from chat will replace   with my username.

By using, you can filter entities of a specific type. For example,  (or  ) will target all pigs. You can also filter out entities of a specific type using :   will say the name of every entity in the world that isn't a pig. You can use  multiple times in a single selector, filtering out two types:. However, you can't use two non-exclusive  arguments in a selector:   is invalid, because an entity cannot be both at the same time.