Steps to reproduce: (from this comment)
- Set bed and spawn a villager in the center of simulation distance. Wait until you see green sparkles before place other bed next to the master bed
- Travel beyond the original simulation distance border so that the village is now unloaded.
- Spawn a villager.
Villager shows green sparkles, running side to side in a holding room, looking at the bed directly as if it was set down next to master bed.
It shouldn't be able to claim bed in an unloaded area or 64 plus away. There is no POI in between.
Villagers claim POIs (Position of Interest) that are unreasonable. i.e. Too far away or unreachable. (Notes: My villagers keep wandering back and forth and won't sleep or find a station.) They end up getting stuck in an unemployed state.
Cure a villager from a zombie villager and keep them in a room.
Make sure there is a bed and a workstation.
Most likely the villager will end up hooking to one of your barrels or a blast furnace you have that's like 50 blocks away for some strange reason..
Possible solution is too minimize the range. 8 blocks or less or just have more weight to the closest block with no chance of claiming a block passed, say, 16 blocks. If the distance is equal, then it will be a random chance. (At least, they should be able to access it to qualify as being a POI.) An untraded villager should still have a chance to change their profession until they are traded with. Villagers should keep their POIs no matter how far in this case. (Or set a timeout of not being able to return to the original POI.) And if it is destroyed you will be able to reassign a different POI. This goes for beds too, except instead of 'work time' it would be 'bed time'. Improved AI would benefit as well to be safe.
I want to add something I noticed. Every time I close and then reopen my world, they all reclaim a bed and it is never one right next to them. The POIs are always like 10s blocks away from them. They won't breed unless I reopen my world as well. It's like something resets each time and needs a refresh every time.