4

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?

  • 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 Turtle Dec 19 '18 at 3:17
  • do I just make a command that constantly changes the entity tags? – Ded Turtle Dec 19 '18 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öling Dec 19 '18 at 7:28
2

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.

  • Note to self: Matching the profession/career changes in 1.14. – Fabian Röling Dec 19 '18 at 8:05
  • is it possible for 1.14? – Ded Turtle May 30 at 1:57
  • 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. – Fabian Röling May 30 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. – Fabian Röling May 30 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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