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 argumentsIf
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:
- Left clicking a
compass
with the displayGame Menu
in the hotbar, opening a GUI window - Left clicking an
orange bed
with the displayBed Wars
, opening another GUI window - Left clicking a
gold block
with the display4v4v4v4
(Joining the lobby)
- Left clicking a
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:
- Right clicking a
compass
in the hotbar, opening a GUI window - Left clicking
orange wool
with the displayCapture the Wool
, opening another GUI window - Left clicking
red wool
with the displayRed Team
(Joining the lobby)
- Right clicking a
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)