• Stars
    star
    213
  • Rank 185,410 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pathfinding plugin that gives bot the ability to go from A to B

Mineflayer-pathfinder

npm version npm Try it on gitpod Issue Hunt

Pathfinding plugin for the Minecraft Bot API Mineflayer. Create static, dynamic or composite goals to navigate Minecraft terrain fully autonomously.

Mostly stable. Feel free to contribute by making suggestions or posting issues.

Install

npm install mineflayer-pathfinder

Tutorial & Explanation

For a basic explanation of how to use mineflayer-pathfinder, you can read this tutorial.

Video Tutorials

For a video tutorial explaining the usage of mineflayer-pathfinder, you can watch the following Youtube videos:

part 1 part 2

Example

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 defaultMove = new Movements(bot)
  
  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))
    } 
  })
})

Features

  • 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
  • Can avoid entities
  • Modular and easily extendable with different behavior

API

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

Functions:

bot.pathfinder.goto(goal)

Returns a Promise with the path result. Resolves when the goal is reached. Rejects on error.

  • goal - Goal instance

bot.pathfinder.bestHarvestTool(block)

Returns the best harvesting tool in the inventory for the specified block.

  • Returns - Item instance or null
  • block - Block instance

bot.pathfinder.getPathTo(movements, goal, timeout)

  • Returns - The path
  • movements - Movements instance
  • goal - Goal instance
  • timeout - number (optional, default bot.pathfinder.thinkTimeout)

bot.pathfinder.getPathFromTo* (movements, startPos, goal, options = {})

Returns a Generator. The generator computes the path for as longs as no full path is found or options.timeout is reached. The generator will block the event loop until a path is found or options.tickTimeout (default to 50ms) is reached.

  • Returns - A generator instance. See MDN function*.
  • movements - Movements instance
  • startPos - A Vec3 instance. The starting position to base the path search from.
  • goal - Goal instance
  • options - A optional options object contains:
    • optimizePath - Boolean Optional. Optimize path for shortcuts like going to the next node in a strait line instead walking only diagonal or along axis.
    • resetEntityIntersects - Boolean Optional. Reset the entityIntersections index for movements. Default: true
    • timeout - Number Optional. Total computation timeout.
    • tickTimeout - Number Optional. Maximum amount off time before yielding.
    • searchRadius - Number Optional. Max distance to search.
    • startMove - instance of Move Optional. A optional starting position as a Move. Replaces startPos as the starting position.

bot.pathfinder.setGoal(Goal, dynamic)

  • goal - Goal instance
  • dynamic - boolean (optional, default false)

bot.pathfinder.setMovements(movements)

Assigns the movements config.

  • movements - Movements instance

bot.pathfinder.stop()

Stops pathfinding as soon as the bot has reached the next node in the path (this prevents the bot from stopping mid-air). Emits path_stop when called. Note: to force stop immediately, use bot.pathfinder.setGoal(null)

bot.pathfinder.isMoving()

A function that checks if the bot is currently moving.

  • Returns - boolean

bot.pathfinder.isMining()

A function that checks if the bot is currently mining blocks.

  • Returns - boolean

bot.pathfinder.isBuilding()

A function that checks if the bot is currently placing blocks.

  • Returns - boolean

Properties:

bot.pathfinder.thinkTimeout

Think Timeout in milliseconds.

  • Default - 5000

bot.pathfinder.tickTimeout

How many milliseconds per tick are allocated to thinking.

  • Default - 40

bot.pathfinder.searchRadius

The search limiting radius, in blocks, if -1 the search is not limited by distance.

  • Default - -1

Movement class

This class configures how pathfinder plans its paths. It configures things like block breaking or different costs for moves. This class can be extended to add or change how pathfinder calculates its moves.

Usage

Pathfinder instantiates the default movement class by itself if no instance is specified. If you want to change values you should create a new instance of the Movements class, change it's values and set it as pathfinders new movement class.

Example:

const { Movements } = require('mineflayer-pathfinder') // Import the Movements class from pathfinder

bot.once('spawn', () => {
  // A new movement instance for specific behavior
  const defaultMove = new Movements(bot)

  defaultMove.allow1by1towers = false // Do not build 1x1 towers when going up
  defaultMove.canDig = false // Disable breaking of blocks when pathing 
  defaultMove.scafoldingBlocks.push(bot.registry.itemsByName['netherrack'].id) // Add nether rack to allowed scaffolding items
  bot.pathfinder.setMovements(defaultMove) // Update the movement instance pathfinder uses

  // Do pathfinder things
  // ...
})

Movements class default properties

Movement class properties and their default values.

canDig

Boolean to allow breaking blocks.

  • Default true

digCost

Additional cost for breaking blocks.

  • Default - 1

placeCost

Additional cost for placing blocks.

  • Default - 1

maxDropDown

Max drop down distance. Only considers drops that have blocks to land on.

  • Default - 4

infiniteLiquidDropdownDistance

Option to ignore maxDropDown distance when the landing position is in water.

  • Default - true

liquidCost

Additional cost for interacting with liquids.

  • Default - 1

entityCost

Additional cost for moving through an entity hitbox (besides passable ones).

  • Default - 1

dontCreateFlow

Do not break blocks that touch liquid blocks.

  • Default - true

dontMineUnderFallingBlock

Do not break blocks that have a gravityBlock above.

  • Default - true

allow1by1towers

Allow pillaring up on 1x1 towers.

  • Default - true

allowFreeMotion

Allow to walk to the next node/goal in a straight line if terrain allows it.

  • Default - false

allowParkour

Allow parkour jumps like jumps over gaps bigger then 1 block.

  • Default - true

allowSprinting

Allow sprinting when moving.

  • Default - true

allowEntityDetection

Test for entities that may obstruct path or prevent block placement. Grabs updated entities every new path.

  • Default - true

entitiesToAvoid

Set of entities (by bot.registry name) to completely avoid when using entity detection.

  • instance of Set

passableEntities

Set of entities (by bot.registry name) to ignore when using entity detection.

  • instance of Set
  • Default - See lib/passableEntities.json

interactableBlocks

Set of blocks (by bot.registry name) that pathfinder should not attempt to place blocks or 'right click' on.

  • instance of Set
  • Default - See lib/interactable.json

blocksCantBreak

Set of block id's pathfinder cannot break. Includes chests and all unbreakable blocks.

  • instance of Set

blocksToAvoid

Set of block id's to avoid.

  • instance of Set

liquids

Set of liquid block id's.

  • instance of Set

climbables

Set of block id's that are climable. Note: Currently unused as pathfinder cannot use climables.

  • instance of Set

replaceables

Set of block id's that can be replaced when placing blocks.

  • instance of Set

scafoldingBlocks

Array of item id's that can be used as scaffolding blocks.

  • Default - [<scaffoldingItems>]

gravityBlocks

Set of block id's that can fall on bot's head.

  • instance of Set

fences

Set of block id's that are fences or blocks that have a collision box taller then 1 block.

  • instance of Set

carpets

Set of all carpet block id's or blocks that have a collision box smaller then 0.1. These blocks are considered safe to walk in.

  • instance of Set

exclusionAreasStep

An array of functions that define an area or block to be step on excluded. Every function in the array is parsed the Block the bot is planing to step on. Each function should return a positive number (includes 0) that defines extra cost for that specific Block. 0 means no extra cost, 100 means it is impossible for pathfinder to consider this move.

  • Array of functions (block: Block) => number

exclusionAreasBreak

An array of functions that define an area or block to be break excluded. Every function in the array is parsed the Block the bot is planing to break. Each function should return a positive number (includes 0) that defines extra cost for that specific Block. 0 means no extra cost, 100 means it is impossible for pathfinder to consider this move.

  • Array of functions (block: Block) => number

exclusionAreasPlace

An array of functions that define an area to be block placement excluded. Every function in the array is parsed the current Block the bot is planing to place a block inside (should be air or a replaceable block most of the time). Each function should return a positive number (includes 0) that defines extra cost for that specific Block. 0 means no extra cost, 100 makes it impossible for pathfinder to consider this move.

  • Array of functions (block: Block) => number

entityIntersections

A dictionary of the number of entities intersecting each floored block coordinate. Updated automatically for each path, but you may mix in your own entries before calculating a path if desired (generally for testing). To prevent this from being cleared automatically before generating a path,s see the path gen options.

  • Formatted entityIntersections['x,y,z'] = #ents
  • Dictionary of costs {string: number}

canOpenDoors

Enable feature to open Fence Gates. Unreliable and known to be buggy.

  • Default - false

Events:

goal_reached

Called when the goal has been reached. Not called for dynamic goals.

path_update

Called whenever the path is recalculated. Status may be:

  • success a path has been found
  • partial a partial path has been found, computations will continue next tick
  • timeout timed out
  • noPath no path was found

goal_updated

Called whenever a new goal is assigned to the pathfinder.

path_reset

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

path_stop

Called when the pathing has been stopped by bot.pathfinder.stop()

Goals:

Goal

Abstract Goal class. Do not instantiate this class. Instead extend it to make a new Goal class.

Has abstract methods:

  • heuristic(node)
    • node - A path node
    • Returns a heuristic number value for a given node. Must be admissible – meaning that it never overestimates the actual cost to get to the goal.
  • isEnd(node)
    • node
    • Returns a boolean value if the given node is a end node.

Implements default methods for:

  • isValid()
    • Always returns true
  • hasChanged(node)
    • node - A path node
    • Always returns false

GoalBlock(x, y, z)

One specific block that the player should stand inside at foot level

  • x - Integer
  • y - Integer
  • z - Integer

GoalNear(x, y, z, range)

A block position that the player should get within a certain radius of

  • x - Integer
  • y - Integer
  • z - Integer
  • range - Integer

GoalXZ(x, z)

Useful for long-range goals that don't have a specific Y level

  • x - Integer
  • z - Integer

GoalNearXZ(x, z, range)

Useful for finding builds that you don't have an exact Y level for, just an approximate X and Z level.

  • x - Integer
  • z - Integer
  • range - Integer

GoalY(y)

Get to a Y level.

  • y - Integer

GoalGetToBlock(x, y, z)

Don't get into the block, but get directly adjacent to it. Useful for chests.

  • x - Integer
  • y - Integer
  • z - Integer

GoalCompositeAny(Array<Goal>?)

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

GoalCompositeAll(Array<Goal>?)

A composite of multiple goals, requiring all of them to be satisfied.

  • Array - Array of goals

GoalInvert(goal)

Inverts the goal.

  • goal - Goal to invert

GoalFollow(entity, range)

Follows an entity.

  • entity - Entity instance
  • range - Integer

GoalPlaceBlock(pos, world, options)

Position the bot in order to place a block.

  • pos - Vec3 the position of the placed block
  • world - the world of the bot (Can be accessed with bot.world)
  • options - object containing all optionals properties:
    • range - maximum distance from the clicked face
    • faces - the directions of the faces the player can click
    • facing - the direction the player must be facing
    • facing3D - boolean, facing is 3D (true) or 2D (false)
    • half - top or bottom, the half that must be clicked

GoalLookAtBlock(pos, world, options = {})

Path into a position were a blockface of block at pos is visible. Fourth argument is optional and contains extra options.

  • pos - Vec3 the block position to look at
  • world - the world of the bot (Can be accessed with bot.world)
  • options - object containing all optionals properties:
    • reach - number maximum distance from the clicked face. Default 4.5
    • entityHeight - number Default is 1.6

GoalBreakBlock(x, y, z, bot, options)

Deprecated. Wrapper for GoalLookAtBlock. Use GoalLookAtBlock instead.

More Repositories

1

mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
JavaScript
4,956
star
2

node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
JavaScript
1,206
star
3

minecraft-data

Language independent module providing minecraft data for minecraft clients, servers and libraries.
JavaScript
657
star
4

flying-squid

Create Minecraft servers with a powerful, stable, and high level JavaScript API.
JavaScript
531
star
5

prismarine-web-client

Minecraft web client running in your browser
JavaScript
437
star
6

bedrock-protocol

Minecraft Bedrock protocol library, with authentication and encryption
JavaScript
311
star
7

prismarine-viewer

Web based viewer for servers and bots
JavaScript
248
star
8

mineflayer-statemachine

A state machine plugin for Mineflayer to aid in designing more complex behavior trees.
TypeScript
108
star
9

node-minecraft-data

Provide easy access to minecraft-data in node.js
JavaScript
100
star
10

prismarine-nbt

An NBT parser for node-minecraft-protocol
JavaScript
93
star
11

prismarine-chunk

A class to hold chunk data for Minecraft
JavaScript
61
star
12

mineflayer-navigate

mineflayer plugin which gives bots a high level 3d navigating API using A*
JavaScript
59
star
13

minecraft-assets

Provide minecraft assets along with json files that help to use them.
59
star
14

node-minecraft-protocol-forge

Plugin to add FML/Forge client support (including auto-versioning) to node-minecraft-protocol
JavaScript
52
star
15

mineflayer-pvp

Adds support for basic PVP and PVE to Mineflayer bots.
TypeScript
50
star
16

prismarine-auth

Microsoft/Xbox Live authentication
JavaScript
48
star
17

node-vec3

3d vector math with robust unit tests
JavaScript
42
star
18

node-yggdrasil

Node.js library to interact with Mojang's authentication system, known as Yggdrasil
JavaScript
40
star
19

prismarine-windows

Represent minecraft windows
JavaScript
37
star
20

mineflayer-radar

(unmaintained) A plugin to give you a web-based radar interface to your mineflayer bot.
JavaScript
36
star
21

mineflayer-collectblock

A simple utility plugin for Mineflayer that add a higher level API for collecting blocks.
TypeScript
36
star
22

prismarine-physics

Provide the physics engine for minecraft entities
JavaScript
35
star
23

prismarine-world

The core implementation of worlds for prismarine
JavaScript
34
star
24

prismarine-chat

A parser for a minecraft chat message
JavaScript
33
star
25

numerous-alpaca

A Minecraft Bedrock Edition server in JavaScript
JavaScript
29
star
26

prismarine-block

Represent a minecraft block with its associated data
JavaScript
29
star
27

prismarine-server

NodeJS Game Server compatible with Minecraft Client
JavaScript
26
star
28

mineflayer-scaffold

mineflayer plugin to build or break blocks to get to a certain point
JavaScript
26
star
29

prismarine-proxy

Provide features to build proxies using Prismarine modules
JavaScript
25
star
30

dazed-sheep

A Minecraft Classic server in JavaScript
JavaScript
24
star
31

MineflayerArmorManager

TypeScript
24
star
32

node-minecraft-wrap

Download and wrap the vanilla minecraft server and client in node.js
JavaScript
24
star
33

prismarine-entity

Represent a minecraft entity
JavaScript
23
star
34

mineflayer-builder

JavaScript
22
star
35

prismarine-schematic

Read and write schematic of any minecraft version, provide them in a convenient and stable API
JavaScript
21
star
36

mineflayer-tool

A tool/weapon selection Mineflayer plugin for automatically selecting the best tool to use for a specific task.
TypeScript
20
star
37

prismarine-item

Represent a minecraft item with its associated data
JavaScript
19
star
38

node-minecraft-assets

Provide minecraft assets in node.js
JavaScript
17
star
39

node-mojangson

A mojangson parser written in node.js
JavaScript
16
star
40

bedrock-provider

Minecraft bedrock level provider for disk and network with caching support
TypeScript
14
star
41

prismarine-contribute

What is PrismarineJS and how to contribute
13
star
42

prismarine-provider-anvil

Anvil Storage Provider implementation.
JavaScript
13
star
43

prismarine-gameplay

A high level gameplay API for making Mineflayer bots.
TypeScript
12
star
44

prismarinejs.github.io

https://prismarinejs.github.io
JavaScript
11
star
45

minecraft-packets

Stores minecraft packets to test implementation of the minecraft protocol
11
star
46

prismarine-realms

Library for interacting with Minecraft Realms
JavaScript
11
star
47

minecraft-wiki-extractor

Extract structured data from the minecraft wiki
JavaScript
10
star
48

prismarine-recipe

Represent minecraft recipes
JavaScript
10
star
49

minecraft-inventory-gui

Render minecraft inventory GUIs in the browser and (soon) headless
JavaScript
10
star
50

diamond-square

A diamond square minecraft generation
JavaScript
9
star
51

minecraft-chunk-dumper

Dumps chunks for any minecraft version
JavaScript
9
star
52

minecraft-classic-protocol

[En][de]code Minecraft 0.30c packets
JavaScript
8
star
53

minecraft-jar-extractor

Extract structured data from the minecraft jar
JavaScript
8
star
54

prismarine-template

A template repository to make it easy to create new prismarine repo
JavaScript
7
star
55

minecraft-data-generator-server

Java
7
star
56

speedrun-challenge-ssgp

JavaScript
7
star
57

mineflayer-cmd

A command handler plugin for Mineflayer.
TypeScript
6
star
58

prismarine-registry

JavaScript
6
star
59

prismarine-biome

Represent a minecraft biome with its associated data
JavaScript
5
star
60

flying-squid-modpe

Flying squid modpe api
JavaScript
4
star
61

mineflayer-test-api

An automated testing library for Mineflayer and Mineflayer plugins with CI/CD.
JavaScript
4
star
62

minecraft-classic-protocol-extension

A plugin for minecraft-classic-protocol that adds experimental and bleeding-edge CPE features
JavaScript
4
star
63

auto-sheep

Automatically update and start dazed-sheep without a githook!
Shell
4
star
64

McDataExtracting

Extract block collision shapes to JSON using Fabric mod loader
Java
4
star
65

node-minecraft-packets

Access minecraft packets examples in node
JavaScript
4
star
66

prismarine-yggdrasil

An implementation of Minecraft's yggdrasil login API
JavaScript
3
star
67

prismarine-rng

JavaScript
3
star
68

gdmc-challenge-2021

The PrismarineJS entry for the 2021 Generative in Design Minecraft Competition.
JavaScript
3
star
69

auto-alpaca

Automatically update and start numerous-alpaca without a githook!
Shell
3
star
70

mineflayer-gptj

JavaScript
3
star
71

prismarine-packet-dumper

Dump minecraft packets
JavaScript
3
star
72

prismarine-updates

Summary of work being done in PrismarineJS modules and user modules, useful for communication
3
star
73

mcdevs-wiki-extractor

Extract structured data from the mcdevs wiki
JavaScript
3
star
74

prismarine-world-sync

A sync proxy to prismarine-world
JavaScript
3
star
75

burger-extractor

Convert burger to minecraft-data
JavaScript
3
star
76

minecraft-assets-pixel-perfection

Assets for the Pixel Perfection pack
GLSL
2
star
77

entity-model-extractor

JavaScript
2
star
78

prismarine-design

Discuss about design and big refactoring that can affects many modules
2
star
79

minecraft-data-auto-updater

Automatically run minecraft data extractors and create pull request for minecraft-data
2
star
80

marketing-and-media

Media/Marketing Materials
1
star
81

prismarine-provider-raw

Raw (prismarine-chunk based) Storage Provider implementation.
JavaScript
1
star
82

prismarine-meta

Make it easy to do chores and maintenance work using the meta package
JavaScript
1
star
83

prismarine-repo-actions

Github Action implementing issue/PR comment commands for repo automation
JavaScript
1
star