2

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.

2 Answers 2

2

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:

/scoreboard players tag @e[type=villager,tag=!profession5] add profession5 {Profession:5}

And then you can target the villager with the particular label:

/effect @e[type=villager,tag=profession5] minecraft:speed

Alternatively, you can use a score instead of a tag label:

/scoreboard objectives add Profession dummy

And the value of the score would represent the profession:

/scoreboard players set @e[type=villager] Profession 5 {Profession:5}

This allows you to easily target a range of professions at the same time, unlike tag labels:

/effect @e[type=villager,score_Profession_min=5,score_Profession=5] minecraft:speed
0

This is a very simple fix, easily done with a Villager with a Custom Name. First, summon a Villager of the desired profession

/summon minecraft:villager ~ ~ ~ {Profession:X,CustomName:"Test",CustomNameVisible:0}

This will summon a Villager named Test.

Now place an always active, unconditional, repeating command block with this command inside:

/effect @e[type=Villager,name=Test] ID Time Amplifier

Replace the name of the villager with whatever you choose, making sure it is contained within the quotations (except when using /testfor, no quotes needed), and replace the ~ ~ ~ with the desired location of the Villager. The profession (X) can be replaced with any of the professions of a Villager (5 is an Illager), but the value has to be a number, not a word. This works with any version, not just 1.11.

Caution: the 5 in 1.11 is an Illager, but in anything below 1.11 it changes back to the first Villager form. For more information, view Skylinerw's link for 1.8, 1.9, and 1.10 NBT tag changes.

2
  • Keep in mind that this will not be helpful if the villagers are naturally-spawned.
    – Skylinerw
    Dec 8, 2016 at 18:48
  • True. This will only work if you summon in the mob via only a Command Block. Dec 24, 2016 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .