mojira.dev
MCPE-42912

Villagers cannot pathfind around walls to their beds

When a villager (v2) tries to go to bed, it can happen that it approaches its claimed bed from the other side of a wall. When this happens, it appears to pathfind through the wall. When it can't reach it, it displays anger particles and wanders for a short time. Sometimes as it wanders it displays green particles as if it discovered the bed again, and sometimes it doesn't, but in either case it can get into a loop trying repeatedly to pathfind through the wall. I have also seen this happen after the villager gets up: It tried to pathfind to its workplace through the wall.

I have attached a test world. To reproduce the problem, simply observe the sole villager for a while.

Linked issues

MCPE-43238 villagers can't find the door Resolved MCPE-46202 Villagers don't understand Walls, "Upstairs", and Chests Resolved MCPE-49497 Villagers won't pathfind through closed wooden doors Resolved MCPE-51721 Bug with houses and Villagers Resolved MCPE-63579 Villager path finding is broken Resolved

Attachments

Comments 38

Sometimes I see a villager who is "try" to walk towards a bed even though there was a villager sleeping in it's bed and the villager (who tries to walk towards an occupied bed) tries to "push" the sleeping villager. Does this happen to you as well?

@Dylan Zosimo: That may be normal behavior. From what I've seen so far, in certain situations a villager can lose ownership of its bed while it's sleeping. Since the second villager doesn't have a bed yet, it claims the bed and tries to lie down, but the first villager is still in it.

I have Noticed this too. Villagers try to pathfind through walls instead of opening the doors and going inside to sleep. Also if it is raining at night they will not sleep at all. Im on Android Samsung galaxy tab A 2017

What I've found in 1.11.0.9 is that if the door they need to go through is within about 5 or 6 blocks of the straight line path from the villager to its bed or job site block, the villager will find the path through the door. Otherwise, they try to walk through the wall and get frustrated. After getting frustrated 3 times, they relinquish the bed or block and search for a replacement, which usually means they find the same bed or block again and the whole cycle repeats until they happen to wander closer to the door.

@unknown: The issue with sleeping when it's raining should be reported separately. It's caused by the fact that when it's raining, most villagers will go inside the first building they come across, even if it's not where their bed is. Then when it's time for bed they're stuck there because they can't use a door while it's raining. Although that's by design, I'm not sure the consequences for sleeping were noticed, so it might be considered a bug.

Tyler Erickson

Still happening in 1.12. Door will be 5 blocks to the side of where the villagers are standing, trying to go through the wall instead of pathing inside.

28 more comments

Noted that this issue also happens if the entrance to the building/house has a dirt path block right in front, villagers wont go through the dirt path to access the building/house.

 

For replicating this just have a building/house with dirt path block in front of the doors or points of entry.

 

*edit: just rephrasing for better conveing what I have observed. Not stating this an easy fix or the whole issue.

Save The Bedrock

@Kolveman,

I can confirm, but I think this is just a small fraction of the pathfinding bug

Suggesting changes to the game's mechanics isn't forbidden. However, it's seldom helpful because we aren't Minecraft devs and don't know the details about how the engine works, or because we aren't CompSci experts and don't know how to think at the necessary level of detail. Brains are really good at solving problems like pathfinding, brainless computers not so much, and translating what the brain does into steps a computer can follow is hard, real hard. Especially if you have to simultaneously make it work well in a practically infinite variety of terrain and structure configurations, and do all this without degrading performance on the least powerful platform you mean to support.

Consider the suggestion made a short time ago to look for a door. It's too high-level and incomplete. It assumes (1) that the first door detected is reachable from where the villager is, and (2) that the target is reachable from that door. But it won't work if the door is behind a wall: The villager will just get stuck on that wall instead. Obviously, that means you should ignore doors that the villager can't reach directly, but that's the same problem as finding a path to a bed you can't reach directly. Although this suggestion makes perfectly good sense to and can easily be used by a brain, a computer has to have much more detailed instructions.

Finding a path from point A to point B is a classic problem in computer science. In theory, it's very simple to solve: You just have to test every possible path and pick the shortest one. But the brute force method explodes exponentially with each additional step required, so that approach isn't practical. So you have to find an alternate method, and it turns out those are always imperfect in one way or another, which is why the villager gets stuck now. What's needed is a different algorithm that works better in this situation and doesn't work worse in other common situations. But an algorithm like that is hard to find and verify, because Minecraft terrain/world generation is so extremely variable.

In summary, this is not so much a bug as it is a shortcoming of the pathfinding algorithm, and the reason it's taking so long to fix is that every conceivable alternative algorithm is going to have shortcomings of its own, most of them with much worse consequences on performance and/or naturalness of behavior. (Which is important: Villagers may seem not quite as smart as people, but at least they don't usually walk off a cliff or drown in a river.)

And then there are the dirt paths. It's easy to draw the wrong conclusion here because the game mechanics are obscure. Villagers don't avoid dirt paths per se; in fact, it's one of a number of blocks they prefer to walk on, all other things being equal. (This means that when a villager is already on a dirt path, they'll tend to follow it in preference to deviating onto grass etc., and sometimes you can make paths to nudge them toward places they need to go to.) I think the reason they avoid paths in cases like this is that dirt paths are shorter than full size blocks, so a villager calculating the best path sees dirt paths as a step downward from grass, dirt, stone, etc. And upward and downward steps (unless there's a stair) are discouraged by the algorithm, so villagers don't do silly things like trying to climb over blocks or dropping into one block holes that happen to be in their way when they could easily walk around them. The algorithm would probably work better if it only discouraged vertical steps of >1/8 block, but I dunno, maybe checking for that on every single pathfinding step would slow things down too much.

In summary, I think Mojang appreciates that we're trying to help, but without knowing the fine details of all the game mechanics, what we suggest is usually too high-level to implement directly, and besides that they've probably already thought of them and either found they won't work, are impractical because of hardware limitations, cause a different problem, or they're already working to implement them. Or, they've already got a fix but it's part of and dependent on an engineering change, some of which isn't ready for prime time yet. That's something that has happened many times. 

Edit: Please don't regard this as an invitation to discuss how to make suggestions better or how you think Mojang needs to change the bug fixing workflow. I posted this to help our Mojira customers understand why fixing bugs sometimes takes a very long time, despite the problem seeming to most people like it's not that difficult. But the bug tracker is not a chat board or other discussion forum; please use the Minecraft Discord for such things.

This is really bad

[media]

Auldrick

(Unassigned)

305639, 204502

Confirmed

Multiple

1803

1.20.10.21 Preview, 1.19.70.26 Preview, 1.14.20 Hotfix, 1.11.0.3 Beta, 1.11.0.5 Beta, ..., 1.21.50, 1.21.60.24 Preview, 1.21.51 Hotfix, 1.21.72 Hotfix, 1.21.80

Retrieved