Skip to content

Latest commit

 

History

History
118 lines (106 loc) · 4.02 KB

README.md

File metadata and controls

118 lines (106 loc) · 4.02 KB

mineflayer-GUI

Manage nested GUI windows in mineflayer using a high level API

^ An example of what a GUI window might be^

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,
  packet: 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
.packet(boolean) // doesn't wait for the server to respond to window transactions (Unstable!)

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)