I'm trying to make a custom world/map that allows you to trade concrete powder. Since this is not a trade normal villagers trade, I will need to find some way to do it. Note that my goal is to change villager trades globally, not just adding a new villager with custom trades. It might be kind of hard to understand, but for example if I want to change say, a cleric to trade concrete powder for an emerald. Can I do that?
-
minecraft.gamepedia.com/Villager#Data_values– Fabian RölingDec 17, 2018 at 7:12
-
could you perhaps provide a tutorial or something like that in the form of another link, I'm not sure I understand how it works yet. It's a bit confusing to understand.– Ded TurtleDec 19, 2018 at 3:17
-
do I just make a command that constantly changes the entity tags?– Ded TurtleDec 19, 2018 at 3:20
-
Oh, I just now noticed that you basically want to change every villager of a career. That's indeed a bit more complicated, since it's not possible with data tags yet (but I've heard rumours that it might be planned for the future). I'll write an answer.– Fabian RölingDec 19, 2018 at 7:28
1 Answer
There is (currently) no way to change a villager type's trades using a data pack. But you can detect the career using commands and then change the trades directly.
This example command makes all clerics trade one stone for one stone one time until it refreshes (so they become the most useful villagers ever):
/execute as @e[type=villager,nbt={Profession:2,Career:1}] run data merge entity @s {Offers:{Recipes:[{buy:{id:stone,Count:1},sell:{id:stone,Count:1},maxUses:1}]},CareerLevel:3}
This command has to be put into an always active repeating command block in the spawn chunks or into a ticking function.
Explanation:
You have to use execute as
with the selector and then data merge entity @s
instead of directly using the selector in /data
, because for some reason that command only allows a single entity. /execute
works around that.
{Profession:2,Career:1}
is the NBT of clerics, so you can filter the villager type that way.
The changed NBT should be pretty self-explanatory, except for CareerLevel:3
, that makes it so that the villager doesn't generate any new trades after the ones you have given him.
I used this villager summon command generator to get a /summon
command for the villager with the correct trades (because I'm lazy, the wiki page (archive) with all the NBT tags would work as well), copied the NBT and removed profession and career from it, since I don't want to change those. Here (archive) are the villager profession/career IDs for matching the right type.
-
-
-
Probably. But there are still many bugs with villagers switching their profession seemingly at random, even some where they repeatedly switch away and back to it while you try to trade with them. So if you want to do anything with villagers, I recommend staying in 1.12.2. May 30, 2019 at 11:38
-
Apparently the NBT now looks like this, was pretty easy to find, even without the wiki:
VillagerData:{profession:"minecraft:librarian",level:1,type:"minecraft:desert"}
But this isn't necessarily persistent, because they can change profession based on various things, so I won't update the answer for now. May 30, 2019 at 11:48