Skip to content

Latest commit

 

History

History
252 lines (165 loc) · 9.43 KB

API.md

File metadata and controls

252 lines (165 loc) · 9.43 KB

Table of Contents generated with DocToc

windows.createWindow(id, type, title, slotCount = undefined)

Create a window with:

  • id - the window id
  • type - this can be a string or a numeric id depending on the mcVersion
  • title - the title of the window
  • slotCount - used to set the number of slots for mcVersion prior to 1.14, ignored in 1.14

windows.Window (base class)

properties

window.id

The protocol id of the window

window.type

Type of the window, can be a string or a numeric id depending on the mcVersion

window.title

Title of the window, shown in the gui.

window.slots

Map of slot index to Item instance. null if the slot is empty.

window.inventoryStart

Slot from where the player inventory start in the window.

window.inventoryEnd

Slot from where the player inventory end in the window.

window.hotbarStart

Slot from where the player hotbar start in the window.

window.craftingResultSlot

Slot for the crafting result if this window has one, -1 otherwise.

window.requiresConfirmation

boolean only false for chests in pre-1.14 versions.

window.selectedItem

In vanilla client, this is the item you are holding with the mouse cursor.

Methods

window.acceptClick(click)

window.acceptOutsideWindowClick(click)

window.acceptInventoryClick(click)

window.acceptNonInventorySwapAreaClick(click)

window.acceptSwapAreaRightClick(click)

window.acceptSwapAreaLeftClick(click)

window.acceptCraftingClick(click)

Change the slot to contain the newItem. Emit the updateSlot events.

Returns a list of changed slots mirroring the Window Click packet format

window.updateSlot(slot, newItem)

Change the slot to contain the newItem. Emit the updateSlot events.

window.findItemRange(start, end, itemType, metadata, [notFull], nbt)

  • start - start slot to begin the search from
  • end - end slot to end the search
  • item - numerical id that you are looking for check the list
  • metadata - metadata value that you are looking for. null means unspecified.
  • notFull - (optional) - if true, means that the returned item should not be at its stackSize.
  • nbt - nbt data for the item you are looking for. null means unspecified

window.findItemRangeName(start, end, itemName, metadata, [notFull])

  • start - start slot to begin the search from
  • end - end slot to end the search
  • item - name that you are looking for check the list
  • metadata - metadata value that you are looking for. null means unspecified.
  • notFull - (optional) - if true, means that the returned item should not be at its stackSize.

window.findInventoryItem(item, metadata, [notFull])

Search in the player inventory.

  • item - numerical id or name that you are looking for check the list
  • metadata - metadata value that you are looking for. null means unspecified.
  • notFull - (optional) - if true, means that the returned item should not be at its stackSize.

window.findContainerItem(item, metadata, [notFull])

Search in the container of the window.

  • item - numerical id or name that you are looking for check the list
  • metadata - metadata value that you are looking for. null means unspecified.
  • notFull - (optional) - if true, means that the returned item should not be at its stackSize.

window.firstEmptySlotRange(start, end)

Return the id of the first empty slot between start and end.

window.firstEmptyHotbarSlot()

Return the id of the first empty slot in the hotbar.

window.firstEmptyContainerSlot()

Return the id of the first empty slot in the container.

window.firstEmptyInventorySlot(hotbarFirst = true)

Return the id of the first empty slot in the inventory, start looking in the hotbar first if the flag is set.

window.countRange (start, end, itemType, metadata)

Returns how many item you have of the given type, between slots start and end.

  • itemType - numerical id that you are looking for
  • metadata - (optional) metadata value that you are looking for. defaults to unspecified

window.itemsRange (start, end)

Returns a list of Item instances between slots start and end.

window.count(itemType, [metadata])

Returns how many you have in the inventory section of the window.

  • itemType - numerical id that you are looking for
  • metadata - (optional) metadata value that you are looking for. defaults to unspecified

window.items()

Returns a list of Item instances from the inventory section of the window.

window.containerCount(itemType, [metadata])

Returns how many you have in the top section of the window.

  • itemType - numerical id that you are looking for
  • metadata - (optional) metadata value that you are looking for. defaults to unspecified

window.containerItems()

Returns a list of Item instances from the top section of the window.

window.emptySlotCount()

Returns how many empty slots you have in the inventory section of the window.

window.transactionRequiresConfirmation(click)

Returns the property: requiresConfirmation.

window.clear([blockId], [count])

Sets all slots in the window to null (unless specified by args)

  • blockId - (optional) numerical id of the block that you would like to clear
  • count - (optional, requires blockId) only delete this number of the given block

Events

window "updateSlot" (slot, oldItem, newItem)

Fired whenever any slot in the window changes for any reason. Watching bot.inventory.on("updateSlot") is the best way to watch for changes in your inventory.

  • slot - index of changed slot.
  • oldItem, newItem - either an Item instance or null.

newItem === window.slots[slot].

window "updateSlot:slot" (oldItem, newItem)

Fired whenever a specific slot in the window changes for any reason.

  • oldItem, newItem - either an Item instance or null.

newItem === window.slots[slot].