top of page
Writer's pictureBenny

Java Coding Class: Selectors

This article explains in-depth everything about selectors in Minecraft. Selectors allow you to affect any entity in the entire world!

First, we need to learn the 5 basic target selectors. These selectors allow you to affect your everyday things with minimal effort.


@a targets all players

@p targets the nearest player

@r targets a random player

@e targets all entities

@s targets the entity that is executing the command (disabled in command blocks)


Now you may be wondering: What is an entity? An entity counts as anything in the game that has AI, or artificial intelligence. A pig, a cow, a player, or even an armor stand count as entities. So do mobs and bosses like the ender dragon and zombie. You can find a list of all entities here: Minecraft Entity List (Java Edition 1.17) (digminecraft.com)


Now that we have learned basic selectors, say I want to kill all the zombies in the world. If I do /kill @e, that would kill every entity, not just zombies. To change this, we can put a bracket after the @e, so it looks like this:


/kill @e[

Now, a big list of words will come up. It should look something like this:

These are all ways you can select entities. You can select a certain amount, ones with certain names, ones that are a certain entity, or all 3! You can navigate these by pressing Tab on your keyboard. We will get to all of these later, but for now, we want to look at the 'type' selector.

If you write the word type after the brackets and then put an equal sign, a list of all the entities will come up. You can type whatever entity you like here. In my case, I chose zombie so my command looks like this:



/kill @e[type=zombie]

This will kill all the zombies in the entire world. But say I want to kill all the entities named Bob. I could do this:


/kill @e[name=Bob]

This would kill all entities in the world named Bob. And you can also use selectors in a lot of other commands as well, pretty much any time you can choose an entity you can use these. For example, in the effect command we can write: /effect give @e[type=skeleton] speed

This would give all skeletons in the world speed!

We can also use multiple selectors as well. For example, say I want to kill all skeletons named Jimmy:


/kill @e[type=skeleton,name=Jimmy]

To separate selectors, we use a comma. It doesn't matter what order we use these in, so it would work just the same the other way around:


/kill @e[name=Jimmy,type=skeleton]


Also, we can use @a for all players:



/kill @a[name=Jimmy]


This would kill all players in the game named Jimmy.


That's all you need to know on how to separate and form selectors, so now I will make a list of all the selectors you can use:


1. advancements

Allows you to select players with specific advancements. for example,


@a[advancements={minecraft:adventure/adventuring_time=true}]

The syntax is a little weird here.

After advancements= you go into a squiggly line section, which you will see a lot of in later Minecraft coding. That goes into minecraft:(the category of achievement you want to select)

and then into a forward slash. Followed by that, enter in the achievement you want, (use underscores for spaces) and then =true, or =false. After that, you can either close the squiggly line bracket or put a comma after 'true' and then repeat the process starting with minecraft: again. This should look something like this if you want to have multiple achievements:



/kill @a[advancements{minecraft:adventure/adventuring_time=true,minecraft:the_end/free_the_end=false}]

Now, on to the next:


2. distance


This allows you to select entities within a certain distance and is certainly helpful.


This uses some advanced number mechanics, but you will get the hang of it soon.


Say I want to target all entities that are exactly 3 blocks in front of me in any direction. The selector would look like this:


@e[distance=3]

This would target all entities that are 3 blocks around me in a circle. But you can also use decimals, as well.


@e[distance=.3]

But say I want to target all entities within a certain amount of blocks. This would look something like this:


@e[distance=..3]

This would target all entities within 3 blocks of me, that is what the .. means in Minecraft coding. '..' means anything below or equal to the number 3, and you can also use decimals:


@e[distance=...3]

I know there's a lot of periods, but bear with me here: this means anything equal to or below the number .3

Now, you can also target all entities out of the circle, so anything 4 or more blocks away from you in this case:


@e[distance=4..]

Decimal rules apply as well:


@e[distance=.4..]

As you already know, this means anything above or equal to .4.


That is all for the distance selector, on to the next.


3. gamemode


This allows you to target players (and only players, obviously) with a certain gamemode.


Basic selectors would look like this:


@a[gamemode=creative]

@a[gamemode=adventure]

@a[gamemode=survival]

@a[gamemode=spectator]

You can also put an exclamation mark before each gamemode to make it 'if player is not in (gamemode) run command'


For example, running the command:


/kill @a[gamemode=!survival]

This would kill all players who are not in survival.

That's it for the gamemode selector, onto the next.


4. level


This allows you to select players with certain levels. You cannot use decimals.

@a[level=45]

This targets all players whose level is 45. That's it for the level selector, on to the next.


5. limit


This targets a certain amount of entities. For example, if I run the command:


/kill @e[limit=5]

This would kill the first 5 entities that spawned in the world, including players. If I run the command:


/kill @e[limit=5,type=zombie]

This would kill the first 5 zombies to spawn in the world. That's it for the limit selector, on to the next.


6. name


This allows you to target any entity with a certain name, and also affects players. For example, if I run the command


/kill @e[name=Jimmy]

This would kill all entities with the name of Jimmy. If a player that has the name Jimmy is in my world as well, he will also die.


Congratulations! You just learned everything there is to selectors. I hope you learned something, as I did as well! As always, see you next class!


~ Benny


44 views

Comments


bottom of page