How do I select two types of entities in Minecraft with the type selector?

I’ve asked this question towards a developer for Minecraft and I thought I’d ask here too since they might not see the question.

How do I select two types of entities in Minecraft?

  • I have little fighting skill. How can I get rid of a Wither?
  • What can I do with Rotten Flesh?
  • Why doesn't the music in Minecraft play all the time?
  • Why aren't there any passive mobs spawning in my single player world?
  • Why do I need to delete the META-INF folder when installing mods?
  • Are enchanted books or direct enchanting better for rare enchantments?
  • For example, something like: /say @e[type=![Player,Item],r=50] (to clarify I also tried type=Item,Player, type=Item,type=Player etc)

    Should select any entity that does not match players or items, so things like Creepers, Ghasts, XPOrbs, PrimedTNT and so on within a radius of 50 blocks and print them to the chat.

    Instead it ignores one of the flags, and works with the other instead.

  • Can I bypass the new launcher?
  • Why isn't my Minecraft LAN server working?
  • Command Blocks In Minercaft Giving items On Kills
  • Setting up a minecraft server on a website
  • How do I summon a chicken zombie jockey with diamond armor using a command block?
  • How do I survive the first night outside?
  • 6 Solutions collect form web for “How do I select 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:

    1. No need to set up an objective.
    2. 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.
    3. Tags are also stored in an entities NBT data, in the Tags tag.

    The most efficient way to select two specific entities at once with the “type” argument is to put two “type” arguments next to each other.

    Ex.

    @e[type=Player,type=Villager]

    Targets only Players and Villagers.

    Ex.

    @r[type=Player,type=Villager]

    Targets only Players and Villagers. However, this target selector picks a random entity within the specified parameters of the argument, whereas the previous selector picked every entity that met the argument’s parameters.

    This could go on indefinitely until you have selected every type of entity in Minecraft (However, that would be a complete waste of time because the same action can be done with @e).

    Please correct any mistakes I may have made.

    For more info on target selector arguments please visit this post from Minecraft Forum.

    http://www.minecraftforum.net/forums/minecraft-discussion/redstone-discussion-and/command-blocks/2477949-minecraft-pc-target-selectors-and-their-arguments

    In Minecraft 1.9, there is a simple way to do it without scoreboards using Chain Command Blocks. For demonstration, I will kill all entities that are not players or items.

    First Command Block: execute @e ~ ~ ~ summon ArmorStand ~ ~ ~ {Invisible:1,NoGravity:1}

    This makes an armor stand in the same spot as every entity. The first command block must be facing into the second command block.

    Second Command Block: execute @e[type=Player] ~ ~ ~ kill @e[type=ArmorStand,c=1]

    This makes all players kill the armor stands that are about to do something.

    Third Command Block: execute @e[type=Item] ~ ~ ~ kill @e[type=ArmorStand,c=1]

    Same as above except with players. You can do this as many times as you want.

    Last Command Block: execute @e[type=ArmorStand] ~ ~ ~ kill @e[c=2] ~ ~ ~

    This makes all armor stands kill themselves and the entity they represented.

    The advantages:

    • Uses armor stands. Why not?
    • Doesn’t require scoreboards

    The disadvantages:

    • If an entity dies/teleports to a far location after the armor stand is summoned but before the armor stands run their commands, some entity that isn’t meant to be killed will be killed

    If you want all of the non-player non-item entities to run a command, just use this:

    Last Command Block: execute @e[type=ArmorStand] ~ ~ ~ execute @e[r=1,c=-1] ~ ~ ~ <command>

    Disadvantages to this:

    • If an entity dies/teleports/leaves the range in under 1ms, the armor stand will execute the command itself

    A much easier way to do this is to use this command:

    /kill @e[type=!Player,r=20] . The exclamation point means to kill everything except the type of entity targeted. You can put this on a redstone clock and it works great. I hope this helped you! 🙂 P.S. you can put as many entities as you want within the command. Just do this: /kill @e[type=!Player,!Sheep,r=20]

    As others later explained to me, the real reason is that restrictions of the same kind owerwrite each other. Sorry, I can’t keep myself from trying to use logic for answering questions I actually don’t know the answer to, losing from sight that things usually are not as logical as I think.


    Original answer:

    I’m not frequently targeting entities, but going on from mineguy1009’s failed answer I figure the following:

    The answer most probably fails because this is parsed like [type = Player AND type = Villager], which of course results in nonsense (it’s not exactly nonsense itself, actually it’s quite a reasonable approach as the comma suggests it would be [type = Player OR type = Villager]).

    However, as you are negating, that’s exactly what you need: [type=!Player, type=!Item] should be parsed as [type != Player AND type != Item]. If you want entities to be of either category from a group, intuitively it should be [![type=!<type1>,type=!<type2>,...],<otherconditions>]. If that doesn’t work, you could still go for inverted groups, which would however get awfully long (as you have to list literally every entitiy which shall be not in your group).

    If this answer fails as well, entity targeting is, yeah, wat.

    We love Playing Games, especially Video Games.