10

I want to give undead mobs in a certain radius instant health potions, but I don't know how to only target undead mobs.

effect give @e[distance=1..7, type=undead] minecraft:instant_health 7 10

But there is no "undead" mob type. At least in this context.

Any help would be appreciated.

1
  • 1
    Instant health hurts undead monsters, instant damage heals them. Makes sense, right? Unless you want to kill them. Then I see why you want to give them instant health. Commented Apr 27, 2021 at 19:26

1 Answer 1

15

Unfortunately, you'll have to have one command for each different mob you want to modify. It is not possible to target a group of mobs in one target selector.

Or is it?

If you just go to your chat and begin typing /effect give @e[type=, you'll notice that in addition to all the different mob listings, there are also entries that begin with a #, and if you try those, you'll notice that they do function as group entries, allowing you to specify a set of entity types contained within that group.

So these are some preset group entries, but they aren't much use to us unless we have one that contains the exact listings of entity types we need. If only there was some way to create our own group entries, hmm…

Well, guess what? With a data pack, you can! In data pack lingo, these # group entries are called entity type tags, and you can create one as part of a data pack. Creating the data pack itself is outside the scope of this post, but once it is created, you can create a file at /data/<namespace>/tags/entity_types/<tag_name>.json, replacing <namespace> and <tag_name> with appropriate values.

The contents of said file are quite simple:

{
  "values": [
    "first_entry",
    "second_entry",
    …
  ]
}

where each set of " " contains the ID of one entity type.

Load your data pack into your world, and you should be able to target your new tag file with @e[type=#<namespace>:<tag name>].

4
  • 1
    You shouldn't really use the minecraft: namespace unless you're Mojang.
    – wizzwizz4
    Commented Apr 28, 2021 at 13:59
  • @ExpertCoder14 So what happens when it becomes one? Your code breaks everywhere it's been copied. By putting it in the minecraft namespace, you make Mojang adding this entity tag a breaking change, thus preventing them from doing so.
    – wizzwizz4
    Commented Apr 28, 2021 at 19:26
  • @SonicBoom2o I'd recommend changing the namespace to something other than minecraft, if you're still early in your world development.
    – wizzwizz4
    Commented Apr 28, 2021 at 19:27
  • @wizzwizz4 A year and a half later, I came across this one again, and looking back, I can agree with what you said. Updated accordingly.
    – One 2 Many
    Commented Oct 16, 2022 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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