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-gui

v3.0.2

Published

Manage nested GUI windows in mineflayer using a high level API

Downloads

52

Readme

API

Type Reference

class PrismarineWindow; // link: https://is.gd/h73B5h
class PrismarineItem;   // link: https://is.gd/ivNm7p

Loading the plugin

const gui = require("mineflayer-gui")

...

bot.loadPlugin(gui.plugin)

Default Setter Values

  • If you prefer, these can be manually set after loading the plugin
bot.gui.Defaults = {
  timeout: 5000,
  window: bot.inventory,
  matchBy: "type",
  mouseButton: "left",
  shiftHeld: false,
  strictMatch: false,
  colourMatch: false,
}

Constructing a "Query"

  • Note: all Setters are optional, the current window will be stored internally

    (And will change per query made)

const Query = new bot.gui.Query()
.timeout(number)
.window(PrismarineWindow) // the starting window (inventory by default)
.matchBy('slot' | 'type' | 'display' | 'lore')
.mouseButton('left' | 'right')
.shiftHeld(boolean) // shift-click window items
.strictMatch(boolean) // if false, only match a portion of the query
.colourMatch(boolean) // if true, match queries can include section sign style colour codes

Methods

  • Specifying multiple match queries will have the same effect for all methods

    (ie, match queries will navigate to the final window, with its intended functionality executed with the last match query)

  • If matchBy is 'type', 'display', or 'lore', Strings are used as arguments

  • If matchBy is 'slot', Numbers are used as arguments instead of Strings.

/*
  Returns the final window in a sequence of match queries
  Returns null if the window timed out
*/
const window: PrismarineWindow? = await Query.getWindow(...matching)

/*
  Returns a list of items matching the final match query
  Returns null if the window timed out
*/
const items: PrismarineItem[]? = await Query.getItems(...matching)

/*
  Returns a list of *clicked* items matching the final match query
  Returns null if the window timed out
*/
const items: PrismarineItem[]? = await Query.clickItems(...matching)
  • Intended use example:
    1. Left clicking a compass with the display Game Menu in the hotbar, opening a GUI window
    2. Left clicking an orange bed with the display Bed Wars, opening another GUI window
    3. Left clicking a gold block with the display 4v4v4v4 (Joining the lobby)
const clickedItems = await new bot.gui.Query()
.matchBy('display')
.clickItems('Game Menu', 'Bed Wars', '4v4v4v4')

// "[ ...PrismarineItem, etc... ]" or "null" if one of the windows timed out
console.log(clickedItems)

Chaining Queries

  • Using bot.gui.advanceWindow, it is possible to chain one large query from multiple complicated queries

    "Why would I want to do this?" You can modify Setters mid-query, allowing for more concise syntax

/*
  Returns the current instance of 'Query' (Builder method)
  Returns null if the window timed out
*/
await Query.advanceWindow(...matching)
  • Intended use example:
    1. Right clicking a compass in the hotbar, opening a GUI window
    2. Left clicking orange wool with the display Capture the Wool, opening another GUI window
    3. Left clicking red wool with the display Red Team (Joining the lobby)
const clickedItems = await new bot.gui.Query()
.mouseButton('right')
.advanceWindow('compass')
.then(Query => Query.matchBy('display')
  .advanceWindow('Capture the Wool'))
.then(Query => Query.clickItems('Red Team'))

// "[ ...PrismarineItem, etc... ]" or "null" if one of the windows timed out
console.log(clickedItems)