The exact mechanics of how a villager generates their next trade are, from the link you posted:
The game first compiles a list of potential offers, and the probability is used to determine whether the offer is included in this list. Then one offer is selected from this list at random to be the actual new offer generated.
So basically, every trade that a villager legitimately has in their list of possible trades, has a chance to go on the list. After the list is built, a single item is chosen from among those that made it onto it, and the chosen item is the villager's new trade. There is always, however, the chance that a villager will generate a new trade, and the list will be empty; when this happens, the villager gets the Gold Purchase trade you're after.
For some types of villagers, this is really unlikely, but priests have a fairly good chance of it, because they only have a dozen possible trades, every one of which is more likely to be off the list than on.
One of you said that the max career level is 4, so I used this command
/summon Villager ~ ~1 ~ {Profession:0,Career:2,CareerLevel:4,Offers:{Recipes:[{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:double_plant,Count:8,tag:{display:{Name:"Coin"}}},sell:{id:wooden_sword,Count:1,tag:{Unbreakable:1,display:{Name:"Sturdy Stick"}}}},{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:double_plant,Count:12,tag:{display:{Name:"Coin"}}},sell:{id:golden_sword,Count:1,tag:{AttributeModifiers:[{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:-.10,Operation:1,UUIDLeast:112181,UUIDMost:524106}],Unbreakable:1,ench:[{id:16,lvl:1}]}}},{rewardExp:0b,maxUses:2147483647,uses:0,buy:{id:double_plant,Count:2,tag:{display:{Name:"Coin"}}},sell:{id:leather,Count:1}}]},Attributes:[{Name:generic.movementSpeed,Base:0}],PersistenceRequired:1,ActiveEffects:[{Id:10,Amplifier:50,Duration:133333333333320,ShowParticles:0b},{Id:21,Amplifier:60,Duration:1333333333333333200}]}
and set the career level at 4, this spawns a villager with a career level of 4 that will trade sunflowers named Coin for certain items. Now I tested this multiple times to make sure I was correct, and I was, setting the career level at 4 will prevent new trades from appearing. I am not sure if this works in 1.9, 1.10 or 1.11 because I still play in 1.8.9.
Best 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):
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 thendata 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.