![MCA Reborn [Fabric/Forge]](https://media.forgecdn.net/avatars/thumbnails/1008/780/256/256/638531792918357805.jpg)
Pathfinding Megathread
Luke100000 opened this issue ยท 9 comments
For pathfinding related issues, just comment here.
- Pathfind beyond their search range to avoid getting stuck (2nd floor, large buildings, caves, ...)
- Pathfind around complex shapes (furniture, bushes, ...)
- Custom danger blacklist (stoves, ... not covered by vanilla danger node)
- Failsafe get-home to avoid switching home/workplace too often
Here's a list of all the common issues found. Both by me after hundreds of hours of playing with the mod, and what i've seen from the comments of other users. (i did test all of these myself)
1- Villagers get stuck behind obstructions, (walls taller than 1 block, fences, wall blocks, and so on) while trying to reach their beds at night. They will get stuck and eventually say "i think i'm lost. I can't find the way home" if the path they take towards their bed is obstructed. (This path always seems to be the one that's closest to their bed.) If there are obstructions on this path, villagers will get stuck every night on the exact same spot. They never try to find an alternative path.
2- Villagers get stuck if their bed is one floor above or bellow them, unless there is direct access to their bed near them. (stairs or slabs, for example) If no direct access is found, they will just be stuck looking up or down, depending on where their bed is, and saying that they can't find their home. If they're outside of buildings, it's the same result. They will just look at the ground, or up at the wall in the upper floor where their bed is, and they'll be stuck there the entire night. (in both issue 1 and 2, villagers tend to eventually, after some days of not being able to reach their beds at night, the assignment to their beds will break and they will forget where they live. They will say "i don't have a home" or "i don't remember where i live".
3- Toddlers and children often struggle with doors. Whether it's day or night, they will struggle a lot just to go through a door. What happens is, they often open and close a door really fast and do not pass through. Other times, they do pass through, and then go back the way they came and rinse and repeat. What this leads to, is that villagers of agestate 2 and 3, tend to never leave a building or a room, or never wander off if they do go outside. At night, what this means, is that they spend most of the night trying to reach their bed and failing, because they don't seem to know how to use doors. The issue is caused by doors, because if you remove the door, they'll pass through just fine.
4- Villagers will climb on top of their workstations. While not inherently game breaking, it can be if the player is using a mod like farmer's delight. It's only made worse if they have chef's delight installed, which adds the cook and Chef professions. They'll get on top of the stove and burn to death.
5- Issue's 1 and 2 also affect how villagers interact with profession blocks. Sometimes, they will not reach their profession blocks. And when they do, sometimes they try to use their profession blocks through walls. If there's a wall behind their profession block, they will go to the wall, and stay the whole time looking at the wall. Same for ceilings or floors.
6- Villagers will on rare occasions simply start moving away from a village or their home, and never turn back. Eventually despawning for good. I've only seen this happening with rivers or oceans tho. In my playthroughs, villagers would float away into the void. This was rare and swimming up to the villagers and ordering them to follow me, fixed it.
7- Villagers will often jump out of 2 or more block tall heights, and then they'll get stuck in places they can't get out of. They'll get stuck in holes, caves and so on.
8- Toddlers, children and other villagers which fit into 1 block tall spaces, will sometimes drown due to this. If there are spaces of 1 block tall or more, villagers will swim to those spaces and then drown. There are other things which happen with water too. Fountains or natural water sources that they can get to. They will swim up, and then, because there's a ceiling or a current, they'll drown.
9- Sometimes, villagers get stuck on fence blocks and aren't able to move. even when ordered to follow by the player. Might have more to do with hitboxes than pathfinding tho.
That's all i can think of. I've tested all of these issues, and have been able to reproduce them all, except for issue 6. I've only seen it during my playthroughs.
Here's an idea if you wanted longer distance bed routing:
-
Copy the chunk data of a village, you might do that over various frames to keep it fast.
-
Then find all the beds in all the copied chunks (and the chunks aren't going to change since you have a copy).
-
Then, gradually over multiple frames to keep it fast, do this marking algorithm:
- Look at any amount of unmarked block that aren't a bed. You can pick a few random ones but it should be in a way that you eventually look at all of them.
- For each block you look at, if it's next to a bed, mark it with "1" and mark it with the direction the bed is in. Or if it's next to a marked block with a number, mark it with that number plus 1 and the direction that block is in. (E.g. if your unmarked block is next to a block marked "1" to the west, and one marked "5" to the south, mark it "2" for lowest number plus 1 and with direction west.)
- Repeat until every block is marked.
You now have a read-only, possibly outdated archived fallback map for where the closest bed is, from every spot near or in the village.
Now whenever you do pathfinding and you can't find a bed in the maximum path finding range, you can instead use this fallback map. It might be outdated and therefore not helpful, but in most cases it's probably going to be useful. And if you redo and update it every minute or so, it's not going to have villagers stuck for too long.
I'm not sure if this will work in practice, just an idea.
I think the key issue with the pathfinding, is that even tho villagers will choose the path that is closest to their beds, they often fail to identify obstructions in the pathing to their beds. It's like they're mistaking a wall or a fence for air nodes, or just aren't being updated to know that there is an obstruction in the air nodes in the pathing they chose for their bed. I think this is why sometimes they get stuck near fences, walls, ceilings or floors, and other blocks, while trying to find their bed. Maybe it would help a lot if there were more regular checks on their air nodes to see if there are obstructions or not. Or at least, have them do a check once they realize they can't reach their bed. You know, when they say "i think i'm lost. I can't find the way home" and then recalculate a new path to their bed. But my Knowledge of coding is very basic so, i'm just spitballing here.
After going through some older replies about the pathfinding issue, if i may add a different suggestion, what about having the villagers teleport to their assigned beds when they say "i think i'm lost. I can't find the way home"? Just when they get stuck, so that immersion isn't sacrificed. Wouldn't it be possible and a lot easier to teleport them to their beds, if their pathing breaks? I think most players would also be quite happy with that compromise.
Hey yall, thanks for the feedback. Just as a heads up, I am going to be working on a new pathfinding system for MCA villagers, so the more weird behavior you can identify, the better.
I've mostly just found two issues: 1. villagers regularly won't return to bed because they get lost in the village, and 2. villagers regularly drop down 2+ blocks into an area that can't be returned from, even when that area is full of enemies, or not lit up at night, or even 3+ blocks down and therefore will lead to fall damage and obviously isn't safe to go to. Might also be that they accidentally push each other to get into this state. This often is a problem when e.g. pits or failed vertical cliff village paths were generated right in the village center.
Both of these issues kind of feel like they might perhaps be avoidable though. Or at least be made less frequent. The combination is bad since it often leads to villagers stranded in monster pits over night.
Good to see this is being looked at! After my comment in #689, I found that keeping teleportation on helps a lot more to prevent villagers randomly disappearing/despawning. If any further villagers disappeared, I think that only happened IF they didn't have a set home/work spot anymore, either because it was obstructed/destroyed, or taken by a different villager.
I've also noticed that, due to villagers usually teleporting to the inn sometime during the day, they usually get 'stuck' there at night (due to the size of my town). They can also switch work/bed spots easily in general, and I imagine it's due to town size & gets more finicky the bigger the area it covers. Giving emeralds to 'lock' villagers into their profession helps the immersion a bit more, but they can still switch workstations (eg. teleport to a different one several houses away, whilst the one they're assigned to is next to their own).
I personally wouldn't mind a more immersion-breaking teleportation honestly, with eg. the work/bed spots being saved as actual coordinates for the villager to teleport to depending on time of day, even if they're out of (chunk) range. In my case, with villagers at the inn at night, I've got to tell em to go home manually to teleport (if they remember their home that is, sometimes it gets reset with 'I don't have a home'). Teleportation doesn't cover the same distance/into inactive chunks when they're trying to pathfind, I think?
Maybe a possible feature (could be assigned to an existing item like the blueprint or a command?), is to list any villagers that don't have a home, optionally workplace, so it's easier to keep track of? A different mod that does this is Liberty's Villagers, but that works better for vanilla villagers/professions. And if it'd be more immersive to keep it locked to rank, maybe unlock it when the player's a Mayor?
Alternatively maybe a custom block that can be set as a spawn/work/inn point for villagers, with optionally the villagers being added to it by 'set location', or by manually inputting their names/uuids like a command block or something? Would probably be very immersion breaking, but might be a helpful alternative for bigger cities/creative. (Or I don't know.. An immersive texture could be a 'welcome mat' or something?)
And an option/feature for villagers to just not despawn unless temporary like adventurers/cultists, despite not having bed/work places would be neat. I know there's some commands for unloaded villagers, but those've never worked for me & neither has skimming NBT/coord files, they're fully gone once that despawn happens & I've got to manually delete their entry in the mca data file.
--
For other misc. pathfinding/position things I haven't seen in the comments above yet:
-
Villagers can float in the water, but if they get in there, they usually just sit in the same spot for the entire day & don't get out of the water. This can obstruct pathfinding/teleportation at night
-
Not a super big deal to me personally (as I've ''dummyfied'' my builds for it), but if door sides when opened, aren't obstructed by a block/wall/pot/whatever, villagers will try to get through the door & constantly open/close it, instead of around. It isn't limited to just toddlers/kids, it happens with any type of villager if doors are setup like that
-
If multiple fence gates are vertically put above one another, villagers can only open/close the bottom one. Any ones above are usually left open/get a similar issue like the doors in point 2 in my experience
-
Villagers can get stuck on top of ladders and not get down, especially if the top's covered by eg. a trapdoor. I presume this happens if the ladder's in their pathfinding, because the ladder issue doesn't happen (to my knowledge) if the ladder's moved in a more ''inconvenient'' place
-
Sometimes when villagers teleport, to eg. the inn, they teleport into 2-block tall spaces that aren't necessarily the floor. In my case, I've got a 4x4 window in the inn, and sometimes they teleport onto that. For now I've ''dummyfied'' it by just placing slabs, so it doesn't count as a valid place to teleport to anymore
-
I THINK they avoid carpets like the plague. Villagers walk around it, not sure if they can actually pathfind onto it, I know this was some thing with vanilla ones a while ago though
-
I've also noticed that villagers have a preference for specific blocks for paths. So my roads in my resource pack are made of coarse dirt, with the road sides being smooth stone slabs. 9/10 times the villagers heavily prefer to walk over the slabs, they can pathfind/walk over the coarse dirt, but usually if they're just walking along the road like eg. guards, they'll be using the smooth stone slabs. I think I've vaguely seen that block preference in the source files? Having that possibly be configurable would be neat
A problem with teleportation is that it doesn't seem to be currently possible to reserve a bed for the player. The common work around for that is iron doors that the villagers can't get through. I imagine with teleportation enabled the villagers would just teleport past them.
This comment is more of a suggestion than anything, but would be good to include in pathfinding: When villager chose a working station have the possibility to configure the village as working station only being able to be used in their corresponding building (help with decorative block a lot) and also have villager pathfind, and stay at their workplace during work hour -> make more sense immersively and in general were you can see villager go to their workstation only when tey need to recharge. Also yeah a better detection of if their stuck because i have the distinc experience of villager falling down and being stuck in cave and just going further and further down the cave. Also small question when is the new pathfinding? Thanks for the answers.