-1

How do I select multiple targets with one command block without using @e[type=!player]? For instance: /execute @e[type=creeper] ~ ~ ~ execute @e[type=spider] ~ ~ ~ execute.... Does this make the command block only execute the next execute command if the previous entity is found?

  • 1
    What Minecraft version? – dly Oct 18 '18 at 8:47
  • Minecraft 1.12.2 – B. De Jong Oct 19 '18 at 14:00
1

1.13 answer:

Selector arguments are and connected, meaning @e[type=creeper,type=spider] selects everything that is both a creeper and a spider (which is nothing).

Chaining just splits up the execution, so execute as @e[type=creeper] as @e[type=spider] does something as every creeper as every spider, meaning every creeper does it as many times as there are spiders loaded.

What you want is an or connection. Minecraft isn't a proper programming language, so you need to repeat your commands for every mob type:

/execute as @e[type=creeper] run <command>
/execute as @e[type=spider] run <command>

Tip: If you have to do this multiple times or your command is very long, tag them:

/tag @e[type=creeper] add spookyScary
/tag @e[type=spider] add spookyScary
/execute as @e[tag=spookyScary] run <command>
/tag @e remove spookyScary

1.12 answer:

Selector arguments are and connected, meaning @e[type=creeper,type=spider] would select everything that is both a creeper and a spider (which is nothing). In actuality, the command just fails if you enter two of the same selector argument in 1.12.

Chaining just splits up the execution, so execute @e[type=creeper] ~ ~ ~ execute @e[type=spider] ~ ~ ~ does something as every creeper as every spider, meaning every creeper does it as many times as there are spiders loaded.

What you want is an or connection. Minecraft isn't a proper programming language, so you need to repeat your commands for every mob type:

/execute @e[type=creeper] ~ ~ ~ <command>
/execute @e[type=spider] ~ ~ ~ <command>

Tip: If you have to do this multiple times or your command is very long, tag them:

/scoreboard players tag @e[type=creeper] add spookyScary
/scoreboard players tag @e[type=spider] add spookyScary
/execute @e[tag=spookyScary] ~ ~ ~ <command>
/scoreboard players tag @e remove spookyScary
  • Note to self: * doesn't work in /tag, don't try to optimise away the @e. ;) – Fabian Röling Oct 18 '18 at 19:39
  • I didn't forgot to change it. I have a pretty old laptop which can only run minecraft properly with optifine, but there is no optifine for 1.13+ versions. – B. De Jong Oct 19 '18 at 14:02
  • Ah, ok. Yes, 1.13 performance is pretty bad. Even on my pretty good laptop I struggle to get 60fps sometimes. Do you also want a 1.12 answer? It's the same principle. – Fabian Röling Oct 19 '18 at 14:03
  • Yes please. (Don't come with a struggle for 60fps to me, I'm struggling for 60 fps with optifine and all settings on fast or off) – B. De Jong Oct 19 '18 at 14:05
  • Yes please (I don't know if you received my comment, because I can't see it anywhere myself so I'll answer again).... oh. There it is. Never mind. – B. De Jong Oct 19 '18 at 14:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.