How do I get a command block to affect a specific type of villager (also known as profession)?
So far I know:
/effect @e[type=villager] minecraft:{effect here}
To affect all villagers, but I don't know how to change the command to only affect a specific profession. I've tried:
/effect @e[type=villager, Profession:5] minecraft:{effect here}
/effect @e[type=villager; Profession:5] minecraft:{effect here}
And also with profession
in brackets and with no separator.
Best Answer
You cannot insert NBT data directly into a selector. You must use a valid selector argument, of which there is none for a villager profession (you can find a list of valid arguments here). Selectors must also not contain spaces.
In order to target based on NBT data, you must use the
/scoreboard
command to assign a label to the target first:And then you can target the villager with the particular label:
Alternatively, you can use a score instead of a tag label:
And the value of the score would represent the profession:
This allows you to easily target a range of professions at the same time, unlike tag labels: