Pathfinding plugin. This is still a work in progress, feel free to contribute by making suggestions.
npm install mineflayer-pathfinder
For a video tutorial explaining the usage of mineflayer-pathfinder, you can watch the following Youtube videos:
const mineflayer = require('mineflayer')
const pathfinder = require('mineflayer-pathfinder').pathfinder
const Movements = require('mineflayer-pathfinder').Movements
const { GoalNear } = require('mineflayer-pathfinder').goals
const bot = mineflayer.createBot({ username: 'Player' })
bot.loadPlugin(pathfinder)
bot.once('spawn', () => {
const mcData = require('minecraft-data')(bot.version)
const defaultMove = new Movements(bot, mcData)
bot.on('chat', function(username, message) {
if (username === bot.username) return
const target = bot.players[username] ? bot.players[username].entity : null
if (message === 'come') {
if (!target) {
bot.chat('I don\'t see you !')
return
}
const p = target.position
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalNear(p.x, p.y, p.z, 1))
}
})
})
- Optimized and modernized A* pathfinding
- Complexe goals can be specified (inspired by baritone goals )
- Customizable movements generator
- Each movement can have a different cost
- Can break/place blocks as part of its deplacement
- Automatically update path when environment change
- Long distance paths
- Can swim
Considering there are a lot of deep changes that are being worked on, it could take some time before it's done
Also, for now, there is only the pathfinder
module, movements
and goals
still need to be done
Returns a Promise. Resolves when the goal is reached. Rejects on error.
goal
- Goal instancecallback
<function>
- (Optional) The callback is passed two arguments(err, result)
, where error isnull
on success.
Returns the best harvest tool in the inventory for the specified block
Returns
-Item
instance ornull
block
- Block instance
Returns
- The pathmovements
- Movements instancegoal
- Goal instancetimeout
- number (optional, defaultbot.pathfinder.thinkTimeout
)
goal
- Goal instancedynamic
- boolean (optional, default false)
Assigns the movements config
movements
- Movements instance
Stops path finding when its save to stop or after the bot encountered an error while path finding. To force stop use bot.pathfinder.setGoal(null). Emits path_stop
when stopped.
A function that checks if the bot is currently moving.
Returns
- boolean
A function that checks if the bot is currently mining blocks.
Returns
- boolean
A function that checks if the bot is currently placing blocks.
Returns
- boolean
Think Timeout in milliseconds
Default
-5000
How many ms per tick are allocated to thinking
Default
-40
The search limiting radius, in blocks, if -1
the search is not limited by distance.
Default
--1
Called when the goal has been reached. Is not called for dynamic goals.
Called whenever the path is recalculated. Status may be:
success
a path has been foundpartial
a partial path has been found, computations will continue next ticktimeout
timed outnoPath
no path was found
Called whenever a new goal is assigned to the pathfinder.
Called when the path is reset, with a reason:
goal_updated
movements_updated
block_updated
chunk_loaded
goal_moved
dig_error
no_scaffolding_blocks
place_error
stuck
Called when the pathing has been stopped by bot.pathfinder.stop()
One specific block that the player should stand inside at foot level
x
- Integery
- Integerz
- Integer
A block position that the player should get within a certain radius of
x
- Integery
- Integerz
- Integerrange
- Integer
Useful for long-range goals that don't have a specific Y level
x
- Integerz
- Integer
Useful for finding builds that you don't have an exact Y level for, just an approximate X and Z level
x
- Integerz
- Integerrange
- Integer
Get to y level
y
- Integer
Don't get into the block, but get directly adjacent to it. Useful for chests.
x
- Integery
- Integerz
- Integer
A composite of many goals, any one of which satisfies the composite. For example, a GoalCompositeAny of block goals for every oak log in loaded chunks would result in it pathing to the easiest oak log to get to
Array
- Array of goals
A composite of many goals, all of them needs to be satisfied.
Array
- Array of goals
Inverts the goal
goal
- Goal to invert
Follows an entity
entity
- Entity instancerange
- Integer
Position the bot in order to place a block
pos
- Vec3 the position of the placed blockworld
- the world of the botoptions
- object containing all optionals properties:range
- maximum distance from the clicked facefaces
- the directions of the faces the player can clickfacing
- the direction the player must be facingfacing3D
- boolean, facing is 3D (true) or 2D (false)half
-top
orbottom
, the half that must be clicked