In this tutorial, we will look at the /kill command and how to select a specific entity (entity = anything in Minecraft that isn’t a block).
!!! CAUTION !!! The /kill @e command removes ALL ENTITIES (that means everything that is not a block). You should NEVER use this command without selectors as it is destructive to any Minecraft project that hasn’t been backed up.
The /kill @e command can remove:
- item frames
- passive mobs (animals)
- hostile mobs (zombies, skeletons etc)
- armor stands
- minecarts
- players
- dropped items
- and more
Which is why it’s crucial to write a selector in a /kill @e command. Selectors are written in square brackets and can look like this: /kill @e[type=sheep,name=jeb_,limit=4,sort=random]
I’ll explain what these individual selectors do. If you’d like to see a complete list, you can find one here, but some selectors have very specific use cases. I will only describe those that are most important.
[name=]
Selects any entity with a given name. This name sadly cannot have spaces, an underscore ( _ ) is usually used instead.
[type=]
Selects a given entity type. Their names are written in lowercase. Entities with multiple words are usually written with an underscore, such as Armor Stand → armor_stand
[sort=]
Sorts the entities selected by the command (it is invoked at the very last, all other conditions are evaluated beforehand.) It modifies the result of the previous selectors. There are three main options:
- [sort=nearest]: selects the closest entity
- [sort=furthest]: selects the furthest (loaded) entity
- [sort=random]: selects a random entity
[limit=]
Defines a limit of how many entities will be killed
[tag=]
Only kills entities with a specific tag (/tag command). Useful to advanced programmers.
[distance=]
Distance from the executing player. Uses two dots to define a range, like:
- [distrance=..2] – closer than two blocks from a player
- [distance=4..] – further than four blocks from a player
- [distance=3..6] – between 3 and 6 blocks away from a player (like a donut shape)
[level=]
Selects players with a specific XP level (green bar above your hotbar). You can also define a range here using dots, like with [distance=].
[scores=]
Searches for an entity with a specific score (/scoreboard command). The syntax (word order in the command) uses curly brackets: /kill @e[scores={scoreboardName=..number}]. As with [distance=] and [level=], you can also use ranges.