Fast, promise based, 3D pathfinding library using A* and D*Lite algorithms, for Mineflayer found under: https://github.com/superjoe30/mineflayer/
- Mineflayer-Pathfinder
- Features
- Table of Contents
- Basic Usage
- Advanced Usage
- Documentation
- bot.pathfinder.to( startPoint, endPoint [, ENUMPathfinder])
- bot.pathfinder.getSuccessors( position)
- bot.pathfinder.getPredecessors( position)
- bot.pathfinder.getBlock( position)
- bot.pathfinder.MAX_EXPANSIONS
- bot.pathfinder.HEURISTIC( startPoint, EndPoint)
- bot.pathfinder.COST
- bot.pathfinder.ENUMPathfinder
- bot.pathfinder.ENUMStatus
- Algorithm Documentation
- Provides high level API for determining paths between two points
- Multiple algorithms for pathfinding, A* and D*Lite
- Often nearly 3 times as fast as mineflayer-navigate
- Exposed internal functions to allow easier user replacement
- Based solely on a promise based API
Firstly, install:
npm install --save cheezbarger/mineflayer-pathfinder
To get started just paste this code into your bot:
const mineflayer = require('mineflayer');
const pathfinder = require('mineflayer-pathfinder');
// Install pathfinder
pathfinder(bot);
bot.on('chat', function(username, message)
{
// Find path to whoever talked
if (message === 'come')
{
bot.pathfinder
.to(
bot.entity.position,
bot.players[username].entity.position
)
.then(function(ReturnState)
{
const path = ReturnState.path;
// Move bot along path and youre done!
});
}
});
The following code illustrates how a rudimentary D* Lite implementation of pathfinding could work. Familiarize yourself with how the pathfinder algorithms work before using them.
const mineflayer = require('mineflayer');
const pathfinder = require('mineflayer-pathfinder');
const move = require('mineflayer-move');
// Install move and pathfinder
pathfinder(bot);
move(bot);
bot.on('chat', function(username, message)
{
if (message === 'come')
{
const endPoint = bot.players[username].entity.position.floored();
const startPoint = bot.entity.position.floored();
const endPoint = bot.players[username].entity.position.floored();
let lastPoint = undefined;
function move(returnState)
{
bot.move.along(returnState.path)
.then(function(moveReturn)
{
const position = bot.entity.position.floored();
if (moveReturn === bot.move.ENUMStatus.Arrived)
{
if (endPoint.equals(position))
resolve(position);
else if (lastPoint && lastPoint.equals(position))
resolve(position);
else
{
lastPoint = position;
returnState.path.replan().then(move);
}
}
else
{
lastPoint = position;
returnState.path.replan().then(move);
}
});
}
bot.pathfind
.to(bot.entity.position, endPoint)
.then(function(returnState)
{
if (returnState.ENUMState === bot.pathfinder.ENUMStatus.Incomplete)
endPoint = returnState.closestPoint;
bot.pathfind
.to(bot.entity.position, endPoint, bot.pathfinder.ENUMPathfinder.DLITE)
.then(move);
});
}
});
Main pathfinder class.
Attempts a path search from the start point to the end point using the provided pathfinder.
startPoint
- the point from which you want to find the pathendPoint
- the end point of the pathENUMPathfinder
- specifies which pathfinding algorithim to use, seebot.pathfinder.ENUMPathfinder
- Defaults to
bot.pathfinder.ENUMPathfinder.ASTAR
- Defaults to
Returns a promise which evaluates to the corresponding ENUMPathfinder
object, see Algorithm Documentation.
Determines positions to which the bot can move from the given position. There is some discussion about how the default function for getSuccessors
works at Default Conditions
position
- coordinates of the position you want to move from
Determines positions from which the bot could have moved to the given position.
position
- coordinates of the position you want to move to
Slightly faster version of bot.blockAt
position
- coordinates of the block from which you want to get data
Integer values which determines the maximum ammount of positions an algorithim will inspect, defaults to 80000.
Determines the heuristic value from the startPoint
to the endPoint
. Defaults to euclidean distance.
Determines the cost value from the startPoint
to the endPoint
. Defaults to bot.pathfinder.HEURISTIC
.
Object with the following properties:
ASTAR
- Refers to the standard A* algorithm, see A* PathfindingDLITE
- Refers to the optimized D* lite algorithm, see D* Lite Pathfinding
Object with the following properties:
Complete
- Occurs when the path could be successfully computedIncomplete
- Occurs when the pathfinder encountered an error or could not compute the complete path
Detailed overview of the algorithms used avaliable at Algorithm Documentation