TransWikia.com

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

Arqade Asked by Codingale on March 24, 2021

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 all but two types of entities in Minecraft?

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.

9 Answers

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.

Correct answer by Codingale on March 24, 2021

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! :)

Answered by idtownie on March 24, 2021

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

Answered by mineguy1009 on March 24, 2021

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]

Answered by FOODFREAK28 on March 24, 2021

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.

Answered by MrLemon on March 24, 2021

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.

Answered by Egor Hans on March 24, 2021

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

Answered by user113642 on March 24, 2021

As of 1.12 you can do @e[type=!Player,type=!Sheep,r=10]. This works as it checks for a non player mob first, then it checks for a non sheep mob. The radius checks for both parameters within the radius. The syntax is correct as the comma separates the datatags and just !Player or !Sheep would not work.

Answered by ThatGuy124816 on March 24, 2021

A interesting way to do this that i just figured out today is to make a custom entity type. As far as i can tell it can't include NBT data tho.

Make a datapack with a .JSON file in this file path,

datapacksExample 1dataexample_2tagsentity_typesexample_3.json

replace "example" as you see fit and put this in the file.

{
  "values":[
    "minecraft:player",
    "minecraft:item"
  ]
}

Then use new target selector.

/kill @e[type=#example_2:example_3]

or better use this one..

/kill @e[type=!#example_2:example_3]

Because the game has so few default entity types i made a bunch of my own today like hostile, hostile_nether, zombies, undead, etc.. and you can even add to vanilla ones by changing "example_2" to "minecraft" and "example_3" to an existing entity type. I added vex to the vanilla "#minecraft:raiders" doing this because they are by far the most dangerous part of a raid and killing the evoker doesn't immediately kill them.

I'm a very late entry but this is better than scoreboard tricks these days and might be useful for anyone who comes across this.

Answered by Bob on March 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP