Properties
bot.registry
Instance of minecraft-data used by the bot. Pass this to constructors that expect an instance of minecraft-data, such as prismarine-block.
bot.world
A sync representation of the world. Check the doc at http://github.com/PrismarineJS/prismarine-world (opens in a new tab)
world "blockUpdate" (oldBlock, newBlock)
Fires when a block updates. Both oldBlock
and newBlock
provided for
comparison.
oldBlock
may be null
with normal block updates.
world "blockUpdate:(x, y, z)" (oldBlock, newBlock)
Fires for a specific point. Both oldBlock
and newBlock
provided for
comparison. All listeners receive null for oldBlock
and newBlock
and get automatically removed when the world is unloaded.
oldBlock
may be null
with normal block updates.
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.heldItem
The item in the bot's hand, represented as a prismarine-item (opens in a new tab) instance specified with arbitrary metadata, nbtdata, etc.
bot.usingHeldItem
Whether the bot is using the item that it's holding, for example eating food or using a shield.
bot.game.levelType
bot.game.dimension
The bot's current dimension, such as overworld
, the_end
or the_nether
.
bot.game.difficulty
bot.game.gameMode
bot.game.hardcore
bot.game.maxPlayers
bot.game.serverBrand
bot.game.minY
minimum y of the world
bot.game.height
world height
bot.physicsEnabled
Enable physics, default true.
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
}
A player's ping starts at 0, you might have to wait a bit for the server to send their actual ping.
bot.players
Map of username to people playing the game.
bot.tablist
bot's tablist object has two keys, header
and footer
.
{
header: { toString: Function }, // ChatMessage object.
footer: { toString: Function } // ChatMessage object.
}
bot.isRaining
bot.rainState
A number indicating the current rain level. When it isn't raining, this will be equal to 0. When it starts to rain, this value will increase gradually up to 1. When it stops raining, this value gradually decreases back to 0.
Each time bot.rainState
is changed, the "weatherUpdate" event is emitted.
bot.thunderState
A number indicating the current thunder level. When there isn't a thunderstorm, this will be equal to 0. When a thunderstorm starts, this value will increase gradually up to 1. When the thunderstorm stops, this value gradually decreases back to 0.
Each time bot.thunderState
is changed, the "weatherUpdate" event is emitted.
This is the same as bot.rainState
, but for thunderstorms.
For thunderstorms, both bot.rainState
and bot.thunderState
will change.
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
Can be a string listed below or a postive number. Choices:
far
(default)normal
short
tiny
bot.settings.difficulty
Same as from server.properties.
bot.settings.skinParts
These boolean Settings control if extra Skin Details on the own players' skin should be visible
bot.settings.skinParts.showCape - boolean
If you have a cape you can turn it off by setting this to false.
bot.settings.skinParts.showJacket - boolean
bot.settings.skinParts.showLeftSleeve - boolean
bot.settings.skinParts.showRightSleeve - boolean
bot.settings.skinParts.showLeftPants - boolean
bot.settings.skinParts.showRightPants - boolean
bot.settings.skinParts.showHat - boolean
bot.settings.enableTextFiltering - boolean
Unused, defaults to false in Notchian (Vanilla) client.
bot.settings.enableServerListing - boolean
This setting is sent to the server to determine whether the player should show up in server listings
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.oxygenLevel
Number in the range [0, 20] respresenting the number of water-icons known as oxygen level.
bot.physics
Edit these numbers to tweak gravity, jump speed, terminal velocity, etc. Do this at your own risk.
bot.fireworkRocketDuration
How many physics ticks worth of firework rocket boost are left.
bot.simpleClick.leftMouse (slot)
abstraction over bot.clickWindow(slot, 0, 0)
bot.simpleClick.rightMouse (slot)
abstraction over bot.clickWindow(slot, 1, 0)
bot.time.doDaylightCycle
Whether or not the gamerule doDaylightCycle is true or false.
bot.time.bigTime
The total number of ticks since day 0.
This value is of type BigInt and is accurate even at very large values. (more than 2^51 - 1 ticks)
bot.time.time
The total numbers of ticks since day 0.
Because the Number limit of Javascript is at 2^51 - 1 bot.time.time becomes inaccurate higher than this limit and the use of bot.time.bigTime is recommended. Realistically though you'll probably never need to use bot.time.bigTime as it will only reach 2^51 - 1 ticks naturally after ~14280821 real years.
bot.time.timeOfDay
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.day
Day of the world.
bot.time.isDay
Whether it is day or not.
Based on whether the current time of day is between 13000 and 23000 ticks.
bot.time.moonPhase
Phase of the moon.
0-7 where 0 is full moon.
bot.time.bigAge
Age of the world, in ticks.
This value is of type BigInt and is accurate even at very large values. (more than 2^51 - 1 ticks)
bot.time.age
Age of the world, in ticks.
Because the Number limit of Javascript is at 2^51 - 1 bot.time.age becomes inaccurate higher than this limit and the use of bot.time.bigAge is recommended. Realistically though you'll probably never need to use bot.time.bigAge as it will only reach 2^51 - 1 ticks naturally after ~14280821 real years.
bot.quickBarSlot
Which quick bar slot is selected (0 - 8).
bot.inventory
A Window
(opens in a new tab) 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 belowNamesidebar
- scoreboard placed in sidebarlist
- scoreboard placed in list0-18
- slots defined in protocol (opens in a new tab)
bot.teams
All teams known to the bot
bot.teamMap
Mapping of member to team. Uses usernames for players and UUIDs for entities.
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 withbot.username
to ignore your own chat)message
- stripped of all color and control characterstranslate
- chat message type. Null for most bukkit chat messagesjsonMsg
- unmodified JSON message from the servermatches
- 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 messagemessage
- stripped of all color and control characterstranslate
- chat message type. Null for most bukkit chat messagesjsonMsg
- unmodified JSON message from the servermatches
- array of returned matches from regular expressions. May be null
"actionBar" (jsonMsg, verified)
Emitted for every server message which appears on the Action Bar.
jsonMsg
- unmodified JSON message from the serververified
-> null if non signed, true if signed and correct, false if signed and incorrect
"message" (jsonMsg, position, sender, verified)
Emitted for every server message, including chats.
-
jsonMsg
- ChatMessage (opens in a new tab) object containing the formatted chat message. Might additionally have the following properties:- unsigned - Unsigned ChatMessage object. Only present in 1.19.2+, and only when the server allows insecure chat and the server modified the chat message without the user's signature
-
position
- (>= 1.8.1): position of Chat message can be- chat
- system
- game_info
-
sender
- UUID of sender if known (1.16+), else null -
verified
-> null if non signed, true if signed and correct, false if signed and incorrect
"messagestr" (message, messagePosition, jsonMsg, sender, verified)
Alias for the "message" event but it calls .toString() on the prismarine-message object to get a string for the message before emitting.
sender
- UUID of sender if known (1.16+), else nullverified
-> null if non signed, true if signed and correct, false if signed and incorrect
"inject_allowed"
Fires when the index file has been loaded, you can load mcData and plugins here but it's better to wait for "spawn" event.
"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.
"resourcePack" (url, hash)
Emitted when the server sends a resource pack.
"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.
"weatherUpdate"
Emitted when either bot.thunderState
or bot.rainState
changes.
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" (reason)
Emitted when you are no longer connected to the server.
reason
is a string explaining why the client was disconnected. (defaults to 'socketClosed')
"error" (err)
Emitted when an error occurs.
"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.
"breath"
Fires when your oxygen level change.
"entityAttributes" (entity)
Fires when an attribute of an entity changes.
"entitySwingArm" (entity)
"entityHurt" (entity)
"entityDead" (entity)
"entityTaming" (entity)
"entityTamed" (entity)
"entityShakingOffWater" (entity)
"entityEatingGrass" (entity)
"entityHandSwap" (entity)
"entityWake" (entity)
"entityEat" (entity)
"entityCriticalEffect" (entity)
"entityMagicCriticalEffect" (entity)
"entityCrouch" (entity)
"entityUncrouch" (entity)
"entityEquip" (entity)
"entitySleep" (entity)
"entitySpawn" (entity)
"entityElytraFlew" (entity)
An entity started elytra flying.
"itemDrop" (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 ridevehicle
- the entity that is the vehicle
"entityUpdate" (entity)
"entityEffect" (entity, effect)
"entityEffectEnd" (entity, effect)
"playerJoined" (player)
"playerUpdated" (player)
"playerLeft" (player)
"blockUpdate" (oldBlock, newBlock)
(It is better to use this event from bot.world instead of bot directly) Fires when a block updates. Both oldBlock
and newBlock
provided for
comparison.
Note that oldBlock
may be null
.
"blockUpdate:(x, y, z)" (oldBlock, newBlock)
(It is better to use this event from bot.world instead of bot directly) Fires for a specific point. Both oldBlock
and newBlock
provided for
comparison.
Note that oldBlock
may be null
.
"blockPlaced" (oldBlock, newBlock)
Fires when bot places block. 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 effectposition
: a Vec3 instance where the sound originatesvolume
: 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 effectsoundCategory
: category of the sound effectposition
: a Vec3 instance where the sound originatesvolume
: 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 noiseinstrument
:id
: integer idname
: 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 (opens in a new tab).
"pistonMove" (block, isPulling, direction)
"chestLidMove" (block, isOpen, block2)
block
: a Block instance, the block whose lid opened. The right block if it's a double chestisOpen
: number of players that have the chest open. 0 if it's closedblock2
: a Block instance, the other half of the block whose lid opened. null if it's not a double chest
"blockBreakProgressObserved" (block, destroyStage, entity)
Fires when the client observes a block in the process of being broken.
block
: a Block instance, the block being brokendestroyStage
: integer corresponding to the destroy progress (0-9)entity
: the entity which is breaking the block.
"blockBreakProgressEnd" (block, entity)
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 brokenentity
: the entity which has stopped breaking the block
"diggingCompleted" (block)
block
- the block that no longer exists
"diggingAborted" (block)
block
- the block that still exists
"usedfirework"
Fires when the bot uses a firework while elytra flying.
"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.
"teamCreated" (team)
Fires when a team is added.
"teamRemoved" (team)
Fires when a team is removed.
"teamUpdated" (team)
Fires when a team is updated.
"teamMemberAdded" (team)
Fires when a team member or multiple members are added to a team.
"teamMemberRemoved" (team)
Fires when a team member or multiple members are removed from a team.
"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.
"heldItemChanged" (heldItem)
Fires when the held item is changed.
"physicsTick" ()
Fires every tick if bot.physicsEnabled is set to true.
"chat:name" (matches)
Fires when the all of a chat pattern's regexs have matches
"particle"
Fires when a particle is created
Functions
bot.blockAt(point, extraInfos=true)
Returns the block at point
or null
if that point is not loaded. If extraInfos
set to true, also returns informations about signs, paintings and block entities (slower).
See Block
.
bot.waitForChunksToLoad()
This function returns a Promise
, with void
as its argument when many chunks have loaded.
bot.blockInSight(maxSteps, vectorLength)
Deprecated, use blockAtCursor
instead.
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 to5/16
.
bot.blockAtCursor(maxDistance=256)
Returns the block at which bot is looking at or null
maxDistance
- The maximum distance the block can be from the eye, defaults to 256.
bot.entityAtCursor(maxDistance=3.5)
Returns the entity at which bot is looking at or null
maxDistance
- The maximum distance the entity can be from the eye, defaults to 3.5.
bot.blockAtEntityCursor(entity=bot.entity, maxDistance=256)
Returns the block at which specific entity is looking at or null
entity
- Entity data asObject
maxDistance
- The maximum distance the block can be from the eye, defaults to 256.
bot.canSeeBlock(block)
Returns true or false depending on whether the bot can see the specified block
.
bot.findBlocks(options)
Finds the closest blocks from the given point.
options
- Options for the search:point
- The start position of the search (center). Default is the bot position.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.useExtraInfo
- To preserve backward compatibility can result in two behavior depending on the type- boolean - Provide your
matching
function more data - noticeably slower aproach - function - Creates two stage maching, if block passes
matching
function it is passed further touseExtraInfo
with additional info
- boolean - Provide your
maxDistance
- The furthest distance for the search, defaults to 16.count
- Number of blocks to find before returning the search. Default to 1. Can return less if not enough blocks are found exploring the whole area.
Returns an array (possibly empty) with the found block coordinates (not the blocks). The array is sorted (closest first)
bot.findBlock(options)
Alias for bot.blockAt(bot.findBlocks(options)[0])
. Return a single block or null
.
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 craftmetadata
- the numerical metadata value of the item you want to craftnull
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 for1
.craftingTable
- aBlock
instance. Ifnull
, 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.
bot.nearestEntity(match = (entity) =>)
Return the nearest entity to the bot, matching the function (default to all entities). Return null if no entity is found.
Example:
const cow = bot.nearestEntity(entity => entity.name.toLowerCase() === 'cow') // we use .toLowercase() because in 1.8 cow was capitalized, for newer versions that can be ommitted
Methods
bot.end(reason)
End the connection with the server.
reason
- Optional string that states the reason of the end.
bot.quit(reason)
Gracefully disconnect from the server with the given reason (defaults to 'disconnect.quitting').
bot.tabComplete(str, [assumeCommand], [sendBlockInSight])
This function returns a Promise
, with matches
as its argument upon completion.
Requests chat completion from the server.
str
- String to complete.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 <username>
". All split messages will be whispered to username.
bot.chatAddPattern(pattern, chatType, description)
Deprecated, use addChatPattern
instead.
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 chatchatType
- the event the bot emits when the pattern matches. Eg: "chat" or "whisper"- 'description ' - Optional, describes what the pattern is for
bot.addChatPattern(name, pattern, chatPatternOptions)
** this is an alias of bot.addChatPatternSet(name, [pattern], chatPatternOptions)
make an event that is called every time the pattern is matched to a message,
the event will be called "chat:name"
, with name being the name passed
name
- the name used to listen for the eventpattern
- regular expression to match to messages recievedchatPatternOptions
- objectrepeat
- defaults to true, whether to listen for this event after the first matchparse
- instead of returning the actual message that was matched, return the capture groups from the regexdeprecated
- (unstable) used by bot.chatAddPattern to keep compatability, likely to be removed
returns a number which can be used with bot.removeChatPattern() to only delete this pattern
bot.addChatPatternSet(name, patterns, chatPatternOptions)
make an event that is called every time all patterns havee been matched to messages,
the event will be called "chat:name"
, with name being the name passed
name
- the name used to listen for the eventpatterns
- array of regular expression to match to messages recievedchatPatternOptions
- objectrepeat
- defaults to true, whether to listen for this event after the first matchparse
- instead of returning the actual message that was matched, return the capture groups from the regex
returns a number which can be used with bot.removeChatPattern() to only delete this patternset
bot.removeChatPattern(name)
removes a chat pattern(s)
name
: string or number
if name is a string, all patterns that have that name will be removed else if name is a number, only that exact pattern will be removed
bot.awaitMessage(...args)
promise that is resolved when one of the messages passed as an arg is resolved
Example:
async function wait () {
await bot.awaitMessage('<flatbot> hello world') // resolves on "hello world" in chat by flatbot
await bot.awaitMessage(['<flatbot> hello', '<flatbot> world']) // resolves on "hello" or "world" in chat by flatbot
await bot.awaitMessage(['<flatbot> hello', '<flatbot> world'], ['<flatbot> im', '<flatbot> batman']) // resolves on "hello" or "world" or "im" or "batman" in chat by flatbot
await bot.awaitMessage('<flatbot> hello', '<flatbot> world') // resolves on "hello" or "world" in chat by flatbot
await bot.awaitMessage(/<flatbot> (.+)/) // resolves on first message matching the regex
}
bot.setSettings(options)
See the bot.settings
property.
bot.loadPlugin(plugin)
Injects a Plugin. Does nothing if the plugin is already loaded.
plugin
- function
function somePlugin (bot, options) {
function someFunction () {
bot.chat('Yay!')
}
bot.myPlugin = {} // Good practice to namespace plugin API
bot.myPlugin.someFunction = someFunction
}
const bot = lodestone.createBot({})
bot.loadPlugin(somePlugin)
bot.once('login', function () {
bot.myPlugin.someFunction() // Yay!
})
bot.loadPlugins(plugins)
Injects plugins see bot.loadPlugin
.
plugins
- array of functions
bot.hasPlugin(plugin)
Checks if the given plugin is loaded (or scheduled to be loaded) on this bot.
bot.sleep(bedBlock)
This function returns a Promise
, with void
as its argument upon completion.
Sleep in a bed. bedBlock
should be a Block
instance which is a bed.
bot.isABed(bedBlock)
Return true if bedBlock
is a bed
bot.wake()
This function returns a Promise
, with void
as its argument upon completion.
Get out of bed.
bot.setControlState(control, state)
This is the main method controlling the bot movements. It works similarly to pressing keys in minecraft. For example forward with state true will make the bot move forward. Forward with state false will make the bot stop moving forward. You may use bot.lookAt in conjunction with this to control movement. The jumper.js example shows how to use this.
control
- one of ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak']state
-true
orfalse
bot.getControlState(control)
Returns true if a control state is toggled.
control
- one of ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak']
bot.clearControlStates()
Sets all controls to off.
bot.getExplosionDamages(entity, position, radius, [rawDamages])
Returns how much damage will be done to the entity in a radius around the position of the explosion.
It will return null
if the entity has no armor and rawDamages is not set to true, since the function can't calculate the damage with armor if there is no armor.
entity
- Entity instanceposition
- Vec3 (opens in a new tab) instanceradius
- the explosion radius as a numberrawDamages
- optional, if true it ignores armor in the calculation
bot.lookAt(point, [force])
This function returns a Promise
, with void
as its argument when you are looking at point
.
point
Vec3 (opens in a new tab) instance - tilts your head so that it is directly facing this point.force
- Seeforce
inbot.look
bot.look(yaw, pitch, [force])
This function returns a Promise
, with void
as its argument called when you are looking at yaw
and pitch
.
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.
bot.updateSign(block, text, back = false)
Changes the text on the sign. On Minecraft 1.20 and newer, a truthy back
will try setting the text on the back of a sign (only visible if not attached to a wall).
bot.equip(item, destination)
This function returns a Promise
, with void
as its argument when you have successfully equipped the item or when you learn that you have failed to equip the item.
Equips an item from your inventory. If the argument item
is of Instance Item
equip will equip this specific item from its window slot. If the argument item
is of type number
equip will equip the first item found with that id searched by rising slot id (Hotbar is searched last. Armor, crafting, crafting result and off-hand slots are excluded).
item
-Item
instance ornumber
for item id. Seewindow.items()
.destination
"hand"
-null
aliases to this"head"
"torso"
"legs"
"feet"
"off-hand"
- when available
bot.unequip(destination)
This function returns a Promise
, with void
as its argument upon completion.
Remove an article of equipment.
bot.tossStack(item)
This function returns a Promise
, with void
as its argument when tossing is done.
item
- the stack of items you wish to toss truthy, you were not able to complete the toss.
bot.toss(itemType, metadata, count)
This function returns a Promise
, with void
as its argument once tossing is complete.
itemType
- numerical id of the item you wish to tossmetadata
- metadata of the item you wish to toss. Usenull
to match any metadatacount
- how many you want to toss.null
is an alias for1
.
bot.elytraFly()
This function returns a Promise
, with void
as its argument once activating
elytra flight is complete. It will throw an Error if it fails.
bot.dig(block, [forceLook = true], [digFace])
This function returns a Promise
, with void
as its argument when the block is broken or you are interrupted.
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 intoforceLook
- (optional) if true, look at the block and start mining instantly. If false, the bot will slowly turn to the block to mine. Additionally, this can be assigned to 'ignore' to prevent the bot from moving it's head at all. Also, this can be assigned to 'raycast' to raycast from the bots head to place where the bot is looking.digFace
- (optional) Default is 'auto' looks at the center of the block and mines the top face. Can also be a vec3 vector of the face the bot should be looking at when digging the block. For example:vec3(0, 1, 0)
when mining the top. Can also be 'raycast' raycast checks if there is a face visible by the bot and mines that face. Useful for servers with anti cheat.
If you call bot.dig twice before the first dig is finished, you will get a fatal 'diggingAborted' error.
bot.stopDigging()
bot.digTime(block)
Tells you how long it will take to dig the block, in milliseconds.
bot.acceptResourcePack()
Accepts resource pack.
bot.denyResourcePack()
Denies resource pack.
bot.placeBlock(referenceBlock, faceVector)
This function returns a Promise
, with void
as its argument when the server confirms that the block has indeed been placed.
referenceBlock
- the block you want to place a new block next tofaceVector
- one of the six cardinal directions, such asnew Vec3(0, 1, 0)
for the top face, indicating which face of thereferenceBlock
to place the block against.
The new block will be placed at referenceBlock.position.plus(faceVector)
.
bot.placeEntity(referenceBlock, faceVector)
This function returns a Promise
, with Entity
as its argument upon completion.
referenceBlock
- the block you want to place the entity next tofaceVector
- one of the six cardinal directions, such asnew Vec3(0, 1, 0)
for the top face, indicating which face of thereferenceBlock
to place the block against.
The new block will be placed at referenceBlock.position.plus(faceVector)
.
bot.activateBlock(block, direction?: Vec3, cursorPos?: Vec3)
This function returns a Promise
, with void
as its argument upon completion.
Punch a note block, open a door, etc.
block
- the block to activatedirection
Optional defaults tonew Vec3(0, 1, 0)
(up). A vector off the direction the container block should be interacted with. Does nothing when a container entity is targeted.cursorPos
Optional defaults tonew Vec3(0.5, 0.5, 0.5)
(block center). The curos position when opening the block instance. This is send with the activate block packet. Does nothing when a container entity is targeted.
bot.activateEntity(entity)
This function returns a Promise
, with void
as its argument upon completion.
Activate an entity, useful for villager for example.
entity
- the entity to activate
bot.activateEntityAt(entity, position)
This function returns a Promise
, with void
as its argument upon completion.
Activate an entity at the given position, useful for armor stands.
entity
- the entity to activateposition
- the world position to click at
bot.consume()
This function returns a Promise
, with void
as its argument when consume ends.
Eat / drink currently held item
bot.fish()
This function returns a Promise
, with void
as its argument when fishing ends.
Use fishing rod
bot.activateItem(offHand=false)
Activates the currently held item. This is how you eat, shoot bows, throw an egg, activate firework rockets, etc.
Optional parameter is false
for main hand and true
for off hand.
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, swing = true)
Attack a player or a mob.
entity
is a type of entity. To get a specific entity use bot.nearestEntity() or bot.entities.swing
Default totrue
. If false the bot does not swing its arm when attacking.
bot.swingArm([hand], showHand)
Play an arm swing animation.
hand
can takeleft
orright
which is the arm that is animated. Default:right
showHand
is a boolean whether to add the hand to the packet, Default:true
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)
This function returns a Promise
, with void
as its argument when the crafting is complete and your inventory is updated.
recipe
- ARecipe
instance. Seebot.recipesFor
.count
- How many times you wish to perform the operation. If you want to craft planks into8
sticks, you would setcount
to2
.null
is an alias for1
.craftingTable
- ABlock
instance, the crafting table you wish to use. If the recipe does not require a crafting table, you may usenull
for this argument.
bot.writeBook(slot, pages)
This function returns a Promise
, with void
as its argument when the writing was successfully or an error occurred.
slot
is in inventory window coordinates (where 36 is the first quickbar slot, etc.).pages
is an array of strings represents the pages.
bot.openContainer(containerBlock or containerEntity, direction?, cursorPos?)
Opens a block container or entity.
containerBlock
orcontainerEntity
The block instance to open or the entity to open.direction
Optional defaults tonew Vec3(0, 1, 0)
(up). A vector off the direction the container block should be interacted with. Does nothing when a container entity is targeted.cursorPos
Optional defaults tonew Vec3(0.5, 0.5, 0.5)
(block center). The curos position when opening the block instance. This is send with the activate block packet. Does nothing when a container entity is targeted.
Returns a promise on a Container
instance which represents the container you are opening.
bot.openChest(chestBlock or minecartchestEntity, direction?, cursorPos?)
Deprecated. Same as openContainer
bot.openFurnace(furnaceBlock)
Returns a promise on a Furnace
instance which represents the furnace you are opening.
bot.openDispenser(dispenserBlock)
Deprecated. Same as openContainer
bot.openEnchantmentTable(enchantmentTableBlock)
Returns a promise on an EnchantmentTable
instance which represents the enchantment table
you are opening.
bot.openAnvil(anvilBlock)
Returns a promise on an anvil
instance which represents the anvil you are opening.
bot.openVillager(villagerEntity)
Returns a promise on a Villager
instance which represents the trading window you are opening.
You can listen to the ready
event on this Villager
to know when it's ready
bot.trade(villagerInstance, tradeIndex, [times])
This function returns a Promise
, with void
as its argument upon completion.
Uses the open villagerInstance
to trade.
bot.setCommandBlock(pos, command, [options])
Set a command block's properties at pos
.
Example options
argument:
{
mode: 2,
trackOutput: true,
conditional: false,
alwaysActive: true
}
options.mode can have 3 values: 0 (SEQUENCE), 1 (AUTO), 2 (REDSTONE) All options attributes are false by default, except mode which is 2 (as to replicate the default command block in Minecraft).
bot.supportFeature(name)
This can be used to check is a specific feature is available in the current Minecraft version. This is usually only required for handling version-specific functionality.
The list of available features can be found inside the ./lib/features.json (opens in a new tab) file.
bot.waitForTicks(ticks)
This is a promise-based function that waits for a given number of in-game ticks to pass before continuing. This is useful for quick timers that need to function with specific timing, regardless of the given physics tick speed of the bot. This is similar to the standard Javascript setTimeout function, but runs on the physics timer of the bot specifically.
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)
This function returns a Promise
, with void
as its argument upon completion.
The only valid mode option at the moment is 0. Shift clicking or mouse dragging is not implemented.
Click on the current window. See details at https://wiki.vg/Protocol#Click_Container (opens in a new tab)
Prefer using bot.simpleClick.*
bot.putSelectedItemRange(start, end, window, slot)
This function returns a Promise
, with void
as its argument upon completion.
Put the item at slot
in the specified range.
bot.putAway(slot)
This function returns a Promise
, with void
as its argument upon completion.
Put the item at slot
in the inventory.
bot.closeWindow(window)
Close the window
.
bot.transfer(options)
This function returns a Promise
, with void
as its argument upon completion.
Transfer some kind of item from one range to an other. options
is an object containing :
window
: Optional. the window where the item will be moveditemType
: the type of the moved itemsmetadata
: Optional. the metadata of the moved itemssourceStart
andsourceEnd
: the source range.sourceEnd
is optional and will default tosourceStart
+ 1destStart
anddestEnd
: the dest Range.destEnd
is optional and will default todestStart
+ 1count
: the amount of items to transfer. Default:1
nbt
: nbt data of the item to transfer. Default:nullish
(ignores nbt)
bot.openBlock(block, direction?: Vec3, cursorPos?: Vec3)
Open a block, for example a chest, returns a promise on the opening Window
.
block
is the block the bot will open.direction
Optional defaults tonew Vec3(0, 1, 0)
(up). A vector off the direction the container block should be interacted with. Does nothing when a container entity is targeted.cursorPos
Optional defaults tonew Vec3(0.5, 0.5, 0.5)
(block center). The curos position when opening the block instance. This is send with the activate block packet. Does nothing when a container entity is targeted.
bot.openEntity(entity)
Open an entity with an inventory, for example a villager, returns a promise on the opening Window
.
entity
is the entity the bot will open
bot.moveSlotItem(sourceSlot, destSlot)
This function returns a Promise
, with void
as its argument upon completion.
Move an item from sourceSlot
to destSlot
in the current window.
bot.updateHeldItem()
Update bot.heldItem
.
bot.getEquipmentDestSlot(destination)
Gets the inventory equipment slot id for the given equipment destination name.
Available destinations are:
- head
- torso
- legs
- feet
- hand
- off-hand
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)
This function returns a Promise
, with void
as its argument when gets fired when the server sets the slot.
Gives the bot the specified item in the specified inventory slot.
slot
is in inventory window coordinates (where 36 is the first quickbar slot, etc.).item
is a prismarine-item (opens in a new tab) instance specified with arbitrary metadata, nbtdata, etc. Ifitem
isnull
, the item at the specified slot is deleted.
If this method changes anything, you can be notified via bot.inventory.on("updateSlot")
.
bot.creative.clearSlot(slot)
This function returns a Promise
, with void
as its argument when gets fired when the server clears the slot.
Makes the sets the item in the slot given to null.
slot
is in inventory window coordinates (where 36 is the first quickbar slot, etc.).
bot.creative.clearInventory()
This function returns a Promise
, with void
as its argument when gets fired when the server clears the slot.
bot.creative.flyTo(destination)
This function returns a Promise
, with void
as its argument when the bot arrives at the destination.
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.
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.