Is there a way to target only undead mobs in a command?
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.
Solution 1:
Assuming you're using a data pack, which you should be doing if this is a big project. Create an entity tag named minecraft:undead
with the following contents:
{
"values": [
"minecraft:drowned",
"minecraft:husk",
"minecraft:phantom",
"minecraft:skeleton",
"minecraft:skeleton_horse",
"minecraft:stray",
"minecraft:wither",
"minecraft:wither_skeleton",
"minecraft:zoglin",
"minecraft:zombie",
"minecraft:zombie_horse",
"minecraft:zombie_villager",
"minecraft:zombified_piglin"
]
}
Then target those entities with the following target selector:
@e[type=#minecraft:undead]
If you're not using a data pack, then have one command per possible entity type, or switch to using a data pack (highly recommended)