So I went to a village with a few lecterns and I got a villager with fortune, so I go back home and get my emeralds and a bunch of other materials that I could trade. But when I finally got enough emeralds, I couldn't find the villager, I keep looking and I think they turned into a farmer. Why did this happen?
Also, when I was trying to get another librarian with fortune, when I broke their lecturn, they stayed as a librarian, even though I didn't trade with them. I'm really struggling with these villagers please help!
Villagers follow specific mechanics/schedules. Each portion of day has very specific functionality.
This is personal observation, and day times are from 'JourneyMap' mod.
In the morning, (0:00 to 2:00) they wander about a bit and socialize. I noticed that villagers can roam quite far afield, and may end up being rather far from their workstations. They can easily end up somewhere from where they can't path back to their stations.
Then, from 2:00 to 7:30, they work. Shortly before 2:00, each villager will try to path to their claimed workstation. If, for whatever reason, villager cannot path back to that station at the time, following happens:
Station becomes unclaimed and another unemployed villager can claim it and go to work on it.
Old owner becomes unemployed if if player never traded with them. This villager then will seek any nearby unclaimed station, and upon finding one, assumes a new profession.
If player traded with a villager, that villager is 'locked in'. They will not become unemployed, they retain their profession and trades, and they will keep wandering about trying to find an unclaimed station of their profession.
At 7:30, villagers head to village center (the bell) and hang out there, gossiping, socializing and breeding. At 10:00, they seek out their beds and sleep.
What this all means:
If you find a villager with trades you like, you should trade with that villager at least once. Or somehow block that villager in with their station so they can't wander away from it. You definitely want to fence the village in, not making it too large, and also avoid large shifts in terrain height. Villager pathing does not do verticals very well. I have a large fenced off village and quite often I would level a librarian to master, only to find them later hanging out in some corner with unrefreshed trades and their lectern manned by some novice. If I place another lectern nearby, and there are no unemployed around, the master will come and claim it soon enough.
Villagers only actively seek out workstations from 2:00 to 7:30. Only during this period can you cause them to shift profession by breaking/replacing the station. Outside of that time, they do not care about their station.
The absolute most fail-safe way to create a trading hall is to have the villager locked in with their bed and crafting station. Make a complete block casing around their bed, leave one block in the front, then put the crafting station in front of that empty block. and seal up the sides. It should look like this:
Leave a one-block layer of air on top of those, then add a roof so the villager can't jump out of that. I have had a trading hall with 80+ villagers locked in this format and they never break unless someone sleeps in a bed by accident and rips a villager out of it, in which case a glitch can sometimes happen where the villager can't claim the bed back for a very long time.
I can't recall having villagers spontaneously desert their chosen profession (e.g. Librarian) for another (e.g. Farmer) profession, even if I haven't traded with them, but I have experienced villagers switching their trades before I can trade with them. For example, if I get a new Librarian who offers a book of Mending as his first trade and I don't immediately trade with him, he may only offer something less desirable like Knockback I by the time I return the next day with emeralds. This has happened to me several times, and it is not a case of mistaken identity because it happens even if I temporarily lock the new villager in a house with his workstation to keep him safe until I return. So I now make it a habit to always have emeralds in my inventory when I place a lectern for a new villager, so when I get the trade I want I can trade immediately to lock the trade in. This might be a bug, I don't know.
My villagers are almost all free-roaming, but in 1.15 I locked a couple in regular houses permanently because they had such good trades (cheap Mending books, Looting III) and I didn't want to risk losing them. I didn't want to put them in a tiny booth, but I didn't want them to escape, either, so at first I traded with them through a window in the house. It turned out to be inconvenient because the villager didn't always come to the window to trade when I wanted him to. So I ended up making a dog door out of a hanging trap door. The opening is only one block high, but when I stand in front of the trap door and click on it, I end up in a crawling position and can crawl into the house without any danger of the villager getting out. There is another trap door on the inside and I exit the house the same way.