Skip to content

Latest commit

 

History

History
1611 lines (1095 loc) · 50.4 KB

api.md

File metadata and controls

1611 lines (1095 loc) · 50.4 KB

Table of Contents generated with DocToc

API

Enums

These enums are stored in the language independent minecraft-data project, and accessed through node-minecraft-data.

minecraft-data

The data is available in node-minecraft-data module

require('minecraft-data')(bot.version) gives you access to it.

mcdata.blocks

blocks indexed by id

mcdata.items

items indexed by id

mcdata.materials

The key is the material. The value is an object with the key as the item id of the tool and the value as the efficiency multiplier.

mcdata.recipes

recipes indexed by id

mcdata.instruments

instruments indexed by id

mcdata.biomes

biomes indexed by id

mcdata.entities

entities indexed by id

Classes

vec3

See andrewrk/node-vec3

All points in mineflayer are supplied as instances of this class.

  • x - south
  • y - up
  • z - west

Functions and methods which require a point argument accept Vec3 instances as well as an array with 3 values, and an object with x, y, and z properties.

mineflayer.Location

Entity

Entities represent players, mobs, and objects. They are emitted in many events, and you can access your own entity with bot.entity. See prismarine-entity

Block

See prismarine-block

Also block.blockEntity is additional field with block entity data as Object

// sign.blockEntity
{
  x: -53,
  y: 88,
  z: 66,
  id: 'minecraft:sign', // 'Sign' in 1.10
  Text1: { toString: Function }, // ChatMessage object
  Text2: { toString: Function }, // ChatMessage object
  Text3: { toString: Function }, // ChatMessage object
  Text4: { toString: Function }, // ChatMessage object
}

Biome

See prismarine-biome

Item

See prismarine-item

windows.Window (base class)

See prismarine-windows

Recipe

See prismarine-recipe

mineflayer.Chest

Represents a single session of opening and closing a chest. See bot.openChest(chestBlock or minecartchestEntity).

chest.window

If the chest is open, this property is a ChestWindow instance. If the chest is closed, this property is null.

chest "open"

Fires when the chest has successfully been opened.

chest "close"

Fires when the chest closes.

chest "updateSlot" (oldItem, newItem)

Fires when the chest you are looking at is updated.

chest.close()

chest.deposit(itemType, metadata, count, [callback])

  • itemType - numerical item id
  • metadata - numerical value. null means match anything.
  • count - how many to deposit. null is an alias to 1.
  • callback(err) - (optional) - called when done depositing

chest.withdraw(itemType, metadata, count, [callback])

  • itemType - numerical item id
  • metadata - numerical value. null means match anything.
  • count - how many to withdraw. null is an alias to 1.
  • callback(err) - (optional) - called when done withdrawing

chest.count(itemType, [metadata])

Return how many of a certain type of item are in the chest.

  • itemType - numerical item id
  • metadata - (optional) numerical value. null means match anything.

chest.items()

Returns a list of Item instances from the chest.

mineflayer.Furnace

See bot.openFurnace(furnaceBlock).

furnace "open"

Fires when the furnace has successfully been opened.

furnace "close"

Fires when the furnace closes.

furnace "update"

Fires when furnace.fuel and/or furnace.progress update.

furnace "updateSlot" (oldItem, newItem)

Fires when a slot in the furnace you have open has updated.

furnace.close()

furnace.takeInput([callback])

  • callback(err, item)

furnace.takeFuel([callback])

  • callback(err, item)

furnace.takeOutput([callback])

  • callback(err, item)

furnace.putInput(itemType, metadata, count, [cb])

furnace.putFuel(itemType, metadata, count, [cb])

furnace.inputItem()

Returns Item instance which is the input.

furnace.fuelItem()

Returns Item instance which is the fuel.

furnace.outputItem()

Returns Item instance which is the output.

furnace.fuel

How much fuel is left between 0 and 1.

furnace.progress

How much cooked the input is between 0 and 1.

mineflayer.Dispenser

See bot.openDispenser(dispenserBlock).

dispenser "open"

Fires when the dispenser has successfully been opened.

dispenser "close"

Fires when the dispenser closes.

dispenser "updateSlot" (oldItem, newItem)

Fires when a slot in the dispenser you have open has updated.

dispenser.close()

dispenser.items()

Returns a list of Item instances from the dispenser.

dispenser.deposit(itemType, metadata, count, [callback])

  • itemType - numerical item id
  • metadata - numerical value. null means match anything.
  • count - how many to deposit. null is an alias to 1.
  • callback(err) - (optional) - called when done depositing

dispenser.withdraw(itemType, metadata, count, [callback])

  • itemType - numerical item id
  • metadata - numerical value. null means match anything.
  • count - how many to withdraw. null is an alias to 1.
  • callback(err) - (optional) - called when done withdrawing

dispenser.count(itemType, [metadata])

Return how many of a certain type of item are in the dispenser.

  • itemType - numerical item id
  • metadata - (optional) numerical value. null means match anything.

mineflayer.EnchantmentTable

See bot.openEnchantmentTable(enchantmentTableBlock).

enchantmentTable "open"

Fires when the enchantment table has successfully been opened.

enchantmentTable "close"

Fires when the enchantment table closes.

enchantmentTable "updateSlot" (oldItem, newItem)

Fires when a slot in the enchantment table you have open has updated.

enchantmentTable "ready"

Fires when enchantmentTable.enchantments is fully populated and you may make a selection by calling enchantmentTable.enchant(choice).

enchantmentTable.close()

enchantmentTable.targetItem()

Gets the target item. This is both the input and the output of the enchantment table.

enchantmentTable.enchantments

Array of length 3 which are the 3 enchantments to choose from. level can be null if the server has not sent the data yet.

Looks like:

[
  {
    "level": 3
  },
  {
    "level": 4
  },
  {
    "level": 9
  }
]

enchantmentTable.enchant(choice, [callback])

  • choice - [0-2], the index of the enchantment you want to pick.
  • callback(err, item) - (optional) called when the item has been enchanted

enchantmentTable.takeTargetItem([callback])

  • callback(err, item)

enchantmentTable.putTargetItem(item, [callback])

  • callback(err)

mineflayer.Villager

See bot.openVillager(villagerEntity).

villager "open"

Fires when the trading window has successfully been opened.

villager "close"

Fires when the trading window closes.

villager "updateSlot" (oldItem, newItem)

Fires when a slot in the trading window has updated.

villager "ready"

Fires when villager.trades is loaded.

villager.close()

villager.trades

Array of trades.

Looks like:

[
  {
    firstInput: Item,
    output: Item,
    hasSecondItem: false,
    secondaryInput: null,
    disabled: false,
    tooluses: 0,
    maxTradeuses: 7
  },
  {
    firstInput: Item,
    output: Item,
    hasSecondItem: false,
    secondaryInput: null,
    disabled: false,
    tooluses: 0,
    maxTradeuses: 7
  },
  {
    firstInput: Item,
    output: Item,
    hasSecondItem: true,
    secondaryInput: Item,
    disabled: false,
    tooluses: 0,
    maxTradeuses: 7
  }
]

mineflayer.ScoreBoard

ScoreBoard.name

Name of the scoreboard.

ScoreBoard.title

The title of the scoreboard (does not always equal the name)

ScoreBoard.itemsMap

An object with all items in the scoreboard in it

{
  wvffle: { name: 'wvffle', value: 3 },
  dzikoysk: { name: 'dzikoysk', value: 6 }
}

ScoreBoard.items

An array with all sorted items in the scoreboard in it

[
  { name: 'dzikoysk', value: 6 },
  { name: 'wvffle', value: 3 }
]

mineflayer.BossBar

BossBar.title

Title of boss bar, instance of ChatMessage

BossBar.health

Percent of boss health, from 0 to 1

BossBar.dividers

Number of boss bar dividers, one of 0, 6, 10, 12, 20

BossBar.entityUUID

Boss bar entity uuid

BossBar.shouldDarkenSky

Determines whether or not to darken the sky

BossBar.isDragonBar

Determines whether or not boss bar is dragon bar

BossBar.createFog

Determines whether or not boss bar creates fog

BossBar.color

Determines what color the boss bar color is, one of pink, blue, red, green, yellow, purple, white

Bot

mineflayer.createBot(options)

Create and return an instance of the class bot. options is an object containing the optional properties :

  • username : default to 'Player'
  • port : default to 25565
  • password : can be omitted (if the tokens are also omitted then it tries to connect in offline mode)
  • host : default to localhost
  • version : default to automatically guessing the version of the server. Example of value : "1.12.2"
  • clientToken : generated if a password is given
  • accessToken : generated if a password is given
  • logErrors : true by default, catch errors and log them
  • keepAlive : send keep alive packets : default to true
  • checkTimeoutInterval : default to 30*1000 (30s), check if keepalive received at that period, disconnect otherwise.
  • loadInternalPlugins : defaults to true
  • plugins : object : defaults to {}
    • pluginName : false : don't load internal plugin with given name ie. pluginName
    • pluginName : true : load internal plugin with given name ie. pluginName even though loadInternalplugins is set to false
    • pluginName : external plugin inject function : loads external plugin, overrides internal plugin with given name ie. pluginName
  • chat
  • colorsEnabled
  • viewDistance
  • difficulty
  • showCape
  • chatLengthLimit : the maximum amount of characters that can be sent in a single message. If this is not set, it will be 100 in < 1.11 and 256 in >= 1.11.

Properties

bot.entity

Your own entity. See Entity.

bot.entities

All nearby entities. This object is a map of entityId to entity.

bot.username

Use this to find out your own name.

bot.spawnPoint

Coordinates to the main spawn point, where all compasses point to.

bot.game.levelType

bot.game.dimension

bot.game.difficulty

bot.game.gameMode

bot.game.hardcore

bot.game.worldHeight

bot.game.maxPlayers

bot.player

Bot's player object

{
  username: 'player',
  displayName: { toString: Function }, // ChatMessage object.
  gamemode: 0,
  ping: 28,
  entity: entity, // null if you are too far away
}

bot.players

Map of username to people playing the game.

bot.isRaining

bot.chatPatterns

This is an array of pattern objects, of the following format: { /regex/, "chattype", "description")

  • /regex/ - a regular expression pattern, that should have at least two capture groups
  • 'chattype' - the type of chat the pattern matches, ex "chat" or "whisper", but can be anything.
  • 'description' - description of what the pattern is for, optional.

bot.settings.chat

Choices:

  • enabled (default)
  • commandsOnly
  • disabled

bot.settings.colorsEnabled

Default true, whether or not you receive color codes in chats from the server.

bot.settings.viewDistance

Choices:

  • far (default)
  • normal
  • short
  • tiny

bot.settings.difficulty

Same as from server.properties.

bot.settings.showCape

If you have a cape you can turn it off by setting this to false.

bot.experience.level

bot.experience.points

Total experience points.

bot.experience.progress

Between 0 and 1 - amount to get to the next level.

bot.health

Number in the range [0, 20] representing the number of half-hearts.

bot.food

Number, in the range [0, 20] representing the number of half-turkey-legs.

bot.foodSaturation

Food saturation acts as a food "overcharge". Food values will not decrease while the saturation is over zero. Players logging in automatically get a saturation of 5.0. Eating food increases the saturation as well as the food bar.

bot.physics

Edit these numbers to tweak gravity, jump speed, terminal velocity, etc. Do this at your own risk.

bot.time.day

Time of the day, in ticks.

Time is based on ticks, where 20 ticks happen every second. There are 24000 ticks in a day, making Minecraft days exactly 20 minutes long.

The time of day is based on the timestamp modulo 24000. 0 is sunrise, 6000 is noon, 12000 is sunset, and 18000 is midnight.

bot.time.age

Age of the world, in ticks.

bot.quickBarSlot

Which quick bar slot is selected (0 - 8).

bot.inventory

A Window instance representing your inventory.

bot.targetDigBlock

The block that you are currently digging, or null.

bot.isSleeping

Boolean, whether or not you are in bed.

bot.scoreboards

All scoreboards known to the bot in an object scoreboard name -> scoreboard.

bot.scoreboard

All scoreboards known to the bot in an object scoreboard displaySlot -> scoreboard.

  • belowName - scoreboard placed in belowName
  • sidebar - scoreboard placed in sidebar
  • list - scoreboard placed in list
  • 0-18 - slots defined in protocol

bot.controlState

An object whose keys are the main control states: ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak'].

Setting values for this object internally calls bot.setControlState.

Events

"chat" (username, message, translate, jsonMsg, matches)

Only emitted when a player chats publicly.

  • username - who said the message (compare with bot.username to ignore your own chat)
  • message - stripped of all color and control characters
  • translate - chat message type. Null for most bukkit chat messages
  • jsonMsg - unmodified JSON message from the server
  • matches - array of returned matches from regular expressions. May be null

"whisper" (username, message, translate, jsonMsg, matches)

Only emitted when a player chats to you privately.

  • username - who said the message
  • message - stripped of all color and control characters
  • translate - chat message type. Null for most bukkit chat messages
  • jsonMsg - unmodified JSON message from the server
  • matches - array of returned matches from regular expressions. May be null

"actionBar" (jsonMsg)

Emitted for every server message which appears on the Action Bar.

  • jsonMsg - unmodified JSON message from the server

"message" (jsonMsg)

Emitted for every server message, including chats.

  • jsonMsg - unmodified JSON message from the server

"login"

Fires after you successfully login to the server. You probably want to wait for the spawn event before doing anything though.

"spawn"

Emitted once after you log in and spawn for the first time and then emitted when you respawn after death.

This is usually the event that you want to listen to before doing anything on the server.

"respawn"

Emitted when you change dimensions and just before you spawn. Usually you want to ignore this event and wait until the "spawn" event instead.

"game"

Emitted when the server changes any of the game properties.

"title"

Emitted when the server sends a title

  • text - title's text

"rain"

Emitted when it starts or stops raining. If you join a server where it is already raining, this event will fire.

"time"

Emitted when the server sends a time update. See bot.time.

"kicked" (reason, loggedIn)

Emitted when the bot is kicked from the server. reason is a chat message explaining why you were kicked. loggedIn is true if the client was kicked after successfully logging in, or false if the kick occurred in the login phase.

"end"

Emitted when you are no longer connected to the server.

"spawnReset"

Fires when you cannot spawn in your bed and your spawn point gets reset.

"death"

Fires when you die.

"health"

Fires when your hp or food change.

"entitySwingArm" (entity)

"entityHurt" (entity)

"entityWake" (entity)

"entityEat" (entity)

"entityCrouch" (entity)

"entityUncrouch" (entity)

"entityEquipmentChange" (entity)

"entitySleep" (entity)

"entitySpawn" (entity)

"playerCollect" (collector, collected)

An entity picked up an item.

  • collector - entity that picked up the item.
  • collected - the entity that was the item on the ground.

"entityGone" (entity)

"entityMoved" (entity)

"entityDetach" (entity, vehicle)

"entityAttach" (entity, vehicle)

An entity is attached to a vehicle, such as a mine cart or boat.

  • entity - the entity hitching a ride
  • vehicle - the entity that is the vehicle

"entityUpdate" (entity)

"entityEffect" (entity, effect)

"entityEffectEnd" (entity, effect)

"playerJoined" (player)

"playerLeft" (player)

"blockUpdate" (oldBlock, newBlock)

Fires when a block updates. Both oldBlock and newBlock provided for comparison.

Note that oldBlock may be null.

"blockUpdate:(x, y, z)" (oldBlock, newBlock)

Fires for a specific point. Both oldBlock and newBlock provided for comparison.

Note that oldBlock may be null.

"chunkColumnLoad" (point)

"chunkColumnUnload" (point)

Fires when a chunk has updated. point is the coordinates to the corner of the chunk with the smallest x, y, and z values.

"soundEffectHeard" (soundName, position, volume, pitch)

Fires when the client hears a named sound effect.

  • soundName: name of the sound effect
  • position: a Vec3 instance where the sound originates
  • volume: floating point volume, 1.0 is 100%
  • pitch: integer pitch, 63 is 100%

"hardcodedSoundEffectHeard" (soundId, soundCategory, position, volume, pitch)

Fires when the client hears a hardcoded sound effect.

  • soundId: id of the sound effect
  • soundCategory: category of the sound effect
  • position: a Vec3 instance where the sound originates
  • volume: floating point volume, 1.0 is 100%
  • pitch: integer pitch, 63 is 100%

"noteHeard" (block, instrument, pitch)

Fires when a note block goes off somewhere.

  • block: a Block instance, the block that emitted the noise
  • instrument:
    • id: integer id
    • name: one of [harp, doubleBass, snareDrum, sticks, bassDrum].
  • pitch: The pitch of the note (between 0-24 inclusive where 0 is the lowest and 24 is the highest). More information about how the pitch values correspond to notes in real life are available on the official Minecraft wiki.

"pistonMove" (block, isPulling, direction)

"chestLidMove" (block, isOpen)

"blockBreakProgressObserved" (block, destroyStage)

Fires when the client observes a block in the process of being broken.

  • block: a Block instance, the block being broken
  • destroyStage: integer corresponding to the destroy progress (0-9)

"blockBreakProgressEnd" (block)

Fires when the client observes a block stops being broken. This occurs whether the process was completed or aborted.

  • block: a Block instance, the block no longer being broken

"diggingCompleted" (block)

  • block - the block that no longer exists

"diggingAborted" (block)

  • block - the block that still exists

"move"

Fires when the bot moves. If you want the current position, use bot.entity.position and for normal moves if you want the previous position, use bot.entity.position.minus(bot.entity.velocity).

"forcedMove"

Fires when the bot is force moved by the server (teleport, spawning, ...). If you want the current position, use bot.entity.position.

"mount"

Fires when you mount an entity such as a minecart. To get access to the entity, use bot.vehicle.

To mount an entity, use mount.

"dismount" (vehicle)

Fires when you dismount from an entity.

"windowOpen" (window)

Fires when you begin using a workbench, chest, brewing stand, etc.

"windowClose" (window)

Fires when you may no longer work with a workbench, chest, etc.

"sleep"

Fires when you sleep.

"wake"

Fires when you wake up.

"experience"

Fires when bot.experience.* has updated.

"scoreboardCreated" (scoreboard)

Fires when a scoreboard is added.

"scoreboardDeleted" (scoreboard)

Fires when a scoreboard is deleted.

"scoreboardTitleChanged" (scoreboard)

Fires when a scoreboard's title is updated.

"scoreUpdated" (scoreboard, item)

Fires when the score of a item in a scoreboard is updated.

"scoreRemoved" (scoreboard, item)

Fires when the score of a item in a scoreboard is removed.

"scoreboardPosition" (position, scoreboard)

Fires when the position of a scoreboard is updated.

"bossBarCreated" (bossBar)

Fires when new boss bar is created.

"bossBarDeleted" (bossBar)

Fires when new boss bar is deleted.

"bossBarUpdated" (bossBar)

Fires when new boss bar is updated.

Functions

bot.blockAt(point)

Returns the block at point or null if that point is not loaded. See Block.

bot.blockInSight(maxSteps, vectorLength)

Returns the block at which bot is looking at or null

  • maxSteps - Number of steps to raytrace, defaults to 256.
  • vectorLength - Length of raytracing vector, defaults to 5/16.

bot.canSeeBlock(block)

Returns true or false depending on whether the bot can see the specified block.

bot.findBlock(options)

Finds the nearest block to the given point.

  • options - Additional options for the search:
    • point - The start position of the search.
    • matching - A function that returns true if the given block is a match. Also supports this value being a block id or array of block ids.
    • maxDistance - The furthest distance for the search, defaults to 16.

This is a simple function, to be used for simple things, for a more complete search using more optimals algorithm, use mineflayer-blockfinder instead which have a very similar API.

bot.canDigBlock(block)

Returns whether block is diggable and within range.

bot.recipesFor(itemType, metadata, minResultCount, craftingTable)

Returns a list of Recipe instances that you could use to craft itemType with metadata.

  • itemType - numerical item id of the thing you want to craft
  • metadata - the numerical metadata value of the item you want to craft null matches any metadata.
  • minResultCount - based on your current inventory, any recipe from the returned list will be able to produce this many items. null is an alias for 1.
  • craftingTable - a Block instance. If null, only recipes that can be performed in your inventory window will be included in the list.

bot.recipesAll(itemType, metadata, craftingTable)

The same as bot.recipesFor except that it does not check wether the bot has enough materials for the recipe.

Methods

bot.end()

End the connection with the server.

bot.quit(reason)

Gracefully disconnect from the server with the given reason (defaults to 'disconnect.quitting').

bot.tabComplete(str, cb, [assumeCommand], [sendBlockInSight])

Requests chat completion from the server.

  • str - String to complete.
  • callback(matches)
    • matches - Array of matching strings.
  • assumeCommand - Field sent to server, defaults to false.
  • sendBlockInSight - Field sent to server, defaults to true. Set this option to false if you want more performance.

bot.chat(message)

Sends a publicly broadcast chat message. Breaks up big messages into multiple chat messages as necessary.

bot.whisper(username, message)

Shortcut for "/tell ". All split messages will be whispered to username.

bot.chatAddPattern(pattern, chatType, description)

Adds a regex pattern to the bot's chat matching. Useful for bukkit servers where the chat format changes a lot.

  • pattern - regular expression to match chat
  • chatType - the event the bot emits when the pattern matches. Eg: "chat" or "whisper"
  • 'description ' - Optional, describes what the pattern is for

bot.setSettings(options)

See the bot.settings property.

bot.loadPlugin(plugin)

Injects a Plugin.

  • plugin - function
function somePlugin(bot, options) {
  function someFunction() {
    bot.chat('Yay!');
  }
  bot.someFunction = someFunction;
}

var bot = mineflayer.createBot(...);
bot.loadPlugin(somePlugin);
bot.once('login', function() {
  bot.someFunction(); // Yay!
});

bot.loadPlugins(plugins)

Injects plugins see bot.loadPlugin.

  • plugins - array of functions

bot.sleep(bedBlock, [cb])

Sleep in a bed. bedBlock should be a Block instance which is a bed. cb can have an err parameter if the bot cannot sleep.

bot.isABed(bedBlock)

Return true if bedBlock is a bed

bot.wake([cb])

Get out of bed. cb can have an err parameter if the bot cannot wake up.

bot.setControlState(control, state)

  • control - one of ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak']
  • state - true or false

bot.clearControlStates()

Sets all controls to off.

bot.lookAt(point, [force], [callback])

  • point - tilts your head so that it is directly facing this point.
  • force - See force in bot.look
  • callback() optional, called when you are looking at point

bot.look(yaw, pitch, [force], [callback])

Set the direction your head is facing.

  • yaw - The number of radians to rotate around the vertical axis, starting from due east. Counter clockwise.
  • pitch - Number of radians to point up or down. 0 means straight forward. pi / 2 means straight up. -pi / 2 means straight down.
  • force - If present and true, skips the smooth server-side transition. Specify this to true if you need the server to know exactly where you are looking, such as for dropping items or shooting arrows. This is not needed for client-side calculation such as walking direction.
  • callback() optional, called when you are looking at yaw and pitch

bot.updateSign(block, text)

Changes the text on the sign.

bot.equip(item, destination, [callback])

Equips an item from your inventory.

  • item - Item instance. See window.items().
  • destination
    • "hand" - null aliases to this
    • "head"
    • "torso"
    • "legs"
    • "feet"
  • callback(error) - optional. called when you have successfully equipped the item or when you learn that you have failed to equip the item.

bot.unequip(destination, [callback])

Remove an article of equipment.

bot.tossStack(item, [callback])

  • item - the stack of items you wish to toss
  • callback(error) - optional, called when tossing is done. if error is truthy, you were not able to complete the toss.

bot.toss(itemType, metadata, count, [callback])

  • itemType - numerical id of the item you wish to toss
  • metadata - metadata of the item you wish to toss. Use null to match any metadata
  • count - how many you want to toss. null is an alias for 1.
  • callback(err) - (optional) called once tossing is complete

bot.dig(block, [callback])

Begin digging into block with the currently equipped item. See also "diggingCompleted" and "diggingAborted" events.

Note that once you begin digging into a block, you may not dig any other blocks until the block has been broken, or you call bot.stopDigging().

  • block - the block to start digging into
  • callback(err) - (optional) called when the block is broken or you are interrupted.

bot.stopDigging()

bot.digTime(block)

Tells you how long it will take to dig the block, in milliseconds.

bot.placeBlock(referenceBlock, faceVector, cb)

  • referenceBlock - the block you want to place a new block next to
  • faceVector - one of the six cardinal directions, such as new Vec3(0, 1, 0) for the top face, indicating which face of the referenceBlock to place the block against.
  • cb will be called when the server confirms that the block has indeed been placed

The new block will be placed at referenceBlock.position.plus(faceVector).

bot.activateBlock(block, [callback])

Punch a note block, open a door, etc.

  • block - the block to activate
  • callback(err) - (optional) called when the block has been activated

bot.activateEntity(entity, [callback])

Activate an entity, useful for villager for example.

  • entity - the entity to activate
  • callback(err) - (optional) called when the entity has been activated

bot.consume(callback)

Eat / drink currently held item

  • callback(error) - called when consume ends

bot.fish(callback)

Use fishing rod

  • callback(error) - called when fishing ends

bot.activateItem()

Activates the currently held item. This is how you eat, shoot bows, throw an egg, etc.

bot.deactivateItem()

Deactivates the currently held item. This is how you release an arrow, stop eating, etc.

bot.useOn(targetEntity)

Use the currently held item on an Entity instance. This is how you apply a saddle and use shears.

bot.attack(entity)

Attack a player or a mob.

bot.swingArm([hand])

Play an arm swing animation.

  • hand can take left or right which is arm that is animated. Default: right

bot.mount(entity)

Mount a vehicle. To get back out, use bot.dismount.

bot.dismount()

Dismounts from the vehicle you are in.

bot.moveVehicle(left,forward)

Moves the vehicle :

  • left can take -1 or 1 : -1 means right, 1 means left
  • forward can take -1 or 1 : -1 means backward, 1 means forward

All the direction are relative to where the bot is looking at

bot.setQuickBarSlot(slot)

  • slot - 0-8 the quick bar slot to select.

bot.craft(recipe, count, craftingTable, [callback])

  • recipe - A Recipe instance. See bot.recipesFor.
  • count - How many times you wish to perform the operation. If you want to craft planks into 8 sticks, you would set count to 2. null is an alias for 1.
  • craftingTable - A Block instance, the crafting table you wish to use. If the recipe does not require a crafting table, you may use null for this argument.
  • callback - (optional) Called when the crafting is complete and your inventory is updated.

bot.writeBook(slot, pages, [callback])

  • slot is in inventory window coordinates (where 36 is the first quickbar slot, etc.).
  • pages is an array of strings represents the pages.
  • callback(error) - optional. called when the writing was successfully or an error occurred.

bot.openChest(chestBlock or minecartchestEntity)

Returns a Chest instance which represents the chest you are opening.

bot.openFurnace(furnaceBlock)

Returns a Furnace instance which represents the furnace you are opening.

bot.openDispenser(dispenserBlock)

Returns a Dispenser instance which represents the dispenser you are opening.

bot.openEnchantmentTable(enchantmentTableBlock)

Returns an EnchantmentTable instance which represents the enchantment table you are opening.

bot.openVillager(villagerEntity)

Returns an Villager instance which represents the trading window you are opening.

bot.trade(villagerInstance, tradeIndex, [times], [cb])

Uses the open villagerInstance to trade.

bot.setCommandBlock(pos, command, track_output)

Set a command block command at pos.

Lower level inventory methods

These are lower level methods for the inventory, they can be useful sometimes but prefer the inventory methods presented above if you can.

bot.clickWindow(slot, mouseButton, mode, cb)

Click on the current window.

bot.putSelectedItemRange(start, end, window, slot, cb)

Put the item at slot in the specified range.

bot.putAway(slot, cb)

Put the item at slot in the inventory.

bot.closeWindow(window)

Close the window.

bot.transfer(options, cb)

Transfer some kind of item from one range to an other. options is an object containing :

  • window : the window where the item will be moved
  • itemType : the type of the moved items
  • metadata : the metadata of the moved items
  • sourceStart and sourceEnd : the source range
  • destStart and destEnd : the dest Range

bot.openBlock(block, Class)

Open a block, for example a chest.

  • block is the block the bot will open
  • Class is the type of window that will be opened

bot.openEntity(entity, Class)

Open an entity with an inventory, for example a villager.

  • entity is the entity the bot will open
  • Class is the type of window that will be opened

bot.moveSlotItem(sourceSlot, destSlot, cb)

Move an item from sourceSlot to destSlot in the current window.

bot.updateHeldItem()

Update bot.heldItem.

bot.creative

This collection of apis is useful in creative mode. Detecting and changing gamemodes is not implemented here, but it is assumed and often required that the bot be in creative mode for these features to work.

bot.creative.setInventorySlot(slot, item, [callback])

Gives the bot the specified item in the specified inventory slot. If called twice on the same slot before first callback exceeds, first callback will have an error parameter

  • slot is in inventory window coordinates (where 36 is the first quickbar slot, etc.).
  • item can presumably be anything, specified with arbitrary metadata, nbtdata, etc. If item is null, the item at the specified slot is deleted.
  • callback(err) (optional) is a callback which gets fired when the servers sets the slot

If this method changes anything, you can be notified via bot.inventory.on("windowUpdate").

bot.creative.flyTo(destination, [cb])

Calls startFlying() and moves at a constant speed through 3d space in a straight line to the destination. destination is a Vec3, and often the x and z coordinates will end with .5. This operation will not work if there is an obstacle in the way, so it is advised to fly very short distances at a time.

When the bot arrives at the destination, cb is called.

This method does not attempt any path finding. It is expected that a path finding implementation will use this method to move < 2 blocks at a time.

To resume normal physics, call stopFlying().

bot.creative.startFlying()

Sets bot.physics.gravity to 0. To resume normal physics, call stopFlying().

This method is useful if you want to hover while digging the ground below you. It is not necessary to call this function before calling flyTo().

Note that while flying, bot.entity.velocity will not be accurate.

bot.creative.stopFlying()

Restores bot.physics.gravity to it's original value.