The Minecraft scripting API currently doesn't expose any pathfinding methods or algorithms to us. Hopefully, one day; but for now, we need to create our scalable and efficient pathfinding algorithms. Here is my take on it with a customizable A* algorithm.
It can be customized to:
- Jump over gaps (such as a bridge missing some pieces)
- Dodge lava
- Dodge or traverse into water
- Not jump over fences/walls (it can still get on them like a normal player, if there is a block next to them shown in Video 1)
- Customize corner-cutting (shown in the videos below)
- Walk/jump over blocks
- Safely fall down a ledge if there is 1 block below
- Works with different entity heights (some entities are taller or shorter) and the BlockSafetyChecker this pathfinder uses can be customized to fit smaller or larger entities
- And, in general, pathfind to locations
To be efficient, it utilizes the new (beta) system.runJob() to process the algorithm en-masse on different hardwares of devices. This allows you to not worry about performance - and for good PCs, have it pathfind almost instantly in reasonable distances. You can see this efficiency in video 2 as I enable the woodcutter. Not only is he finding the nearest wood block, but then he is pathfinding to it. All of this is calculated almost instantly - as he begins moving towards the tree within milliseconds.
Code and usage: https://github.com/nox7/mc-bedrock-script-utilities/tree/main/Pathfinder
Video examples attached