npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mineflayer-navigate-promise

v0.2.0

Published

thin wrapper around the mineflayer-navigate plugin, to work with promises instead of events

Downloads

14

Readme

mineflayer-navigate-promise

A thin wrapper around the mineflayer-navigate plugin which enables your mineflayer bot to navigate. For a description on the mineflayer-navigate plugin see https://github.com/PrismarineJS/mineflayer-navigate. The injected methods of this plugin are completely preserved and can be used as indicated. This module adds additional methods as described below.

Motivation: I build this in order to use the navigation of my bot in a more convenient way. Especially when it comes to perform some tasks in a sequential way it turns out to be useful to support promises (e.g. walk to some place and interact with the chest there).

See also the mineflayer project from PrismarineJS at https://github.com/PrismarineJS/mineflayer

Documentation

In the following sections the functions are described and short usage examples are provided. See the examples/test.js file for a more detailed example and also see the examples in the mineflayer-navigate project.

bot.navigate.promise.to(destination, options)

Finds a path to the destination and walks there. It calls the bot.navigate.to function from the mineflayer-navigate module.

  • destination - the block you want to go
  • options - see the mineflayer-navigate documentation for it

This returns a promise which will be in a pending state as long as the navigation (find path and walk along) process takes place. Once fulfilled the bot has reached its destination. If the promise gets rejected you will find one of the following reasons in the returned error object:

  • "aborted": Returned whenever a pending navigation process is interfered by some other calls to the navigation module. This applies also if you call bot.navigate.promise.to again while one promise is still pending.
  • "cannotFind": Returned when a path could not be found.
  • "obstructed": Returned when the bot finds itself in an strange state (e.g. on top of a fence and is unable to move further)

Note that whenever the promise is rejected the position of the bot may already have changed.

Promises enable you to use those nice language features like the sequential looking programs you get under the use of await:

try {
  await bot.navigate.promise.to(target.position);
  bot.chat(`destination reached :)`);
} catch (err) {
  bot.chat(`error (message=${err.message})`);
}

Or you could use it more traditional with the .then() method.

bot.navigate.promise.findPath(destination, [options])

  • destination - the block you want to go
  • options - consult the mineflayer-navigate documentation for it

Finds a path to the destination and returns a promise for it. Once fulfilled it contains the path (consisting of a sequence of points, including the starting point and destination). A rejected promise will contain one of the following messages in the error object:

  • "noPath": A path could not be found.
  • "timeout": The process timed out before obtaining a path.
  • "tooFar": The destination is out of reach.

Example see below.

bot.navigate.promise.walk(path)

Walks the bot along the given path and resolves once it has arrived. If errors occur the promise will be rejected with an error object containing the reason for it ("obstructed" or "interrupted"). Note that whenever the promise is rejected the position of the bot may already have changed.

Here is an example call:

try {
  const path = await bot.navigate.promise.findPath(target.position);
  await bot.navigate.promise.walk(path);
  bot.chat('promise resolved, i am here :)');
} catch (err) {
  bot.chat(`problems :( (message=${err.message})`);
}

Notes

License: MIT