How do I select all but two types of entities in Minecraft with the type selector?
First, create a dummy scoreboard objective:
/scoreboard objectives add selectMe dummy
Then, on a fast redstone clock, give all entities a selectMe
score of 1:
/scoreboard players set @e selectMe 1
Give all players and items a selectMe score of 0 with these two command blocks:
/scoreboard players set @e[type=Player] selectMe 0
/scoreboard players set @e[type=Item] selectMe 0
Now, you can select them by targeting all entities within a 50 block radius that have a selectMe score of 1:
/say @e[score_selectMe_min=1,r=50]
Hope this helped! :)
As of Minecraft 1.9, scoreboard tags are a better fit for this than setting up an objective and assigning a score.
It's as easy as setting up repeat command blocks (or a repeat/chain line) and putting:
/scoreboard players tag @e[type=Player] add playerOrItem
/scoreboard players tag @e[type=Item] add playerOrItem
You can then use @e[tag=playerOrItem]
and @e[tag=!playerOrItem]
to select every entity that is and is not a player or item, respectively.
The benefits of using tags over scoreboard objectives are:
- No need to set up an objective.
- They are initialized as empty by default. I.e.
@a[tag=!banana]
works on every player by default, unlike@a[score_banana=0]
. The means you only need to affect the targets you actually want to affect. - Tags are also stored in an entities NBT data, in the
Tags
tag.
As of Minecraft 1.13 (Java Edition) you can now use multiple selectors to target entities.
From the Minecraft Wiki:
tag=foo,tag=bar,tag=!baz matches someone with foo, bar and not baz.
type=!cow,type=!chicken matches something that isn't a cow and isn't a chicken.
type=cow,type=chicken isn't allowed, because something cannot both be a cow and chicken.
For versions prior to 1.13
You can use either idtownie or this from user113642 the latter being untested.