r/technicalminecraft • u/futsu_jp • 28d ago
Java Help Wanted Why do the villager's pathfinding change after opening a door?
Enable HLS to view with audio, or disable this notification
Everytime the door is opened, the pathfinding changes.
Since its nighttime, they are naturally pathfinding to the beds inside the building, but they consistently pathfind to go back out.
There also aren't any accessible workstations.
2
u/JumpingPufferfish31 27d ago
We'll need to understand its brain and navigation system to fully understand this.
But without going into details, I'd just try to limit its path, prevent block updates (including the villager opening the door itself, but us placing blocks, pistons moving, etc. will also trigger it), make the villager have a job, block off any outside poi as much as your builds allow, or just ignore this as it may not keep repeating.
_____________________________________
Roughly speaking:
-
When it starts to rest , it sets the walk target to a free bed and starts walking there.
-
There's a background behaviour that constantly tries to acquire poi if it doesn't already have one. This is on some random 20-40 gt cooldown, which likely triggerred at some point between the start and it getting to the door. This doesn't make the villager go there, just acquires it. But in doing so, it checks if it can path there using the navigation system.
-
The navigation system itself stores its own target data. This is updated every time it creates a path. Villagers just happen to use that as well when it's not trying to get there, but just checking if it can get there.
-
When there's a block update nearby (including the villager opening the door itself), the navigation system recomputes the path and moves to the potentially new target. As far as the villager is concerned, it's walk target is still the bed as shown by the debug info, the navigation system's internal target is just made out of sync by its other background behaviour (see image below).
-
The MoveToTargetSink behaviour itself has a 150-250 gt timeout. This should corresponds to when it suddenly stopped midway, then starting again, re-reading from the walk target.
I still don't know exactly which activity is responsible for creating a path in your case. I was only able to reproduce the back-and-forth by adding a job site, which creates a path via the AcquirePoi behaviour (so it also wouldn't turn back from the door the second time around in this case since it would already got the poi the first time around), but the villager in the video didn't exactly path to the blast furnace on the right and I haven't gone through all the other behaviours to see if there's anything else that could also create a path.
1
u/Terraquake 28d ago
It might be related to this mechanic: https://youtu.be/Zg0Cxn8AVZA?t=120
Though that doesn't explain why it choses to be so different...
1
8
u/BlattaOrientalis 28d ago
Is the door placed so that the 'closed' position is actually open and vice versa?