PrismarineJS / mineflayer-navigate

mineflayer plugin which gives bots a high level 3d navigating API using A*
59 stars 22 forks source link

mineflayer-navigate

NPM version Build Status

Deprecated package : this library is a simple example of pathfinding and works well for the simple cases, you can study its code. However if you need something more robust, we advise to use https://github.com/Karang/mineflayer-pathfinder instead

A library to help your mineflayer bot navigate around the 3D world using the A* algorithm.

See https://github.com/superjoe30/mineflayer/

YouTube Demo

Usage

const mineflayer = require('mineflayer');
const navigatePlugin = require('mineflayer-navigate')(mineflayer);
const bot = mineflayer.createBot({ username: 'Player' });
// install the plugin
navigatePlugin(bot);
// optional configuration
bot.navigate.blocksToAvoid[132] = true; // avoid tripwire
bot.navigate.blocksToAvoid[59] = false; // ok to trample crops
bot.navigate.on('pathFound', function (path) {
  bot.chat("found path. I can get there in " + path.length + " moves.");
});
bot.navigate.on('cannotFind', function (closestPath) {
  bot.chat("unable to find path. getting as close as possible");
  bot.navigate.walk(closestPath);
});
bot.navigate.on('arrived', function () {
  bot.chat("I have arrived");
});
bot.navigate.on('interrupted', function() {
  bot.chat("stopping");
});
bot.on('chat', function(username, message) {
  // navigate to whoever talks
  if (username === bot.username) return;
  const target = bot.players[username].entity;
  if (message === 'come') {
    bot.navigate.to(target.position);
  } else if (message === 'stop') {
    bot.navigate.stop();
  }
});

Documentation

bot.navigate.to(point, options)

Finds a path to the specified location and goes there.

event "pathPartFound" (path)

Emitted from bot.navigate when a partial path is found. path is an array of nodes.

event "pathFound" (path)

Emitted from bot.navigate when a complete path is found. path is an array of nodes.

event "cannotFind" (closestPoint)

Emitted when a path cannot be found.

event "arrived"

Emitted when the destination is reached.

event "stop"

Emitted when navigation has been aborted.

bot.navigate.stop()

Aborts an in progress navigation job.

bot.navigate.findPathSync(end, [options])

Finds a path to end. Can be used to see if it is possible to navigate to a particular point.

Returns an object that looks like:

{
  status: 'success', // one of ['success', 'noPath', 'timeout', 'tooFar']
  path: [startPoint, point1, point2, ..., endPoint],
}

The value of status has several meanings:

Parameters:

bot.navigate.walk(path, [callback])

Note: does not emit events

Walks the bot along the path and calls the callback function when it has arrived.

Call bot.navigate.stop() to interrupt walking.

History

0.0.10

0.0.9

0.0.8

0.0.7

0.0.6

0.0.5

0.0.4

0.0.3

0.0.2