Skip to content

BotPath

A path a bot has searched with Bot:findPath: the way it would walk to a target, from node to node. A spell can look at it before the bot takes a step, for example to compare the ways to two targets, or to see whether a way leads through a place the bot should avoid, and then let the bot walk along it with Bot:startPathAlong.

A path tells how the world was when it was searched. It doesn't change when blocks do, and it can't be changed by a spell. To let a bot walk another way, give Bot:findPath a list of positions to come by.

Example

local path = bot:findPath(spell.pos, { jumps = true })
if path and path.reachable then
  print(string.format("%.1f blocks, %d jumps", path.length, path.jumpCount))
  for _, node in ipairs(path.nodes) do
    spell:execute(string.format("particle minecraft:end_rod %s %s %s", node.x, node.y + 0.5, node.z))
  end
end

Fields

jumpCount: number — Read-Only

The number of jumps across gaps on the path. 0 for a path searched without the option jumps.

length: number — Read-Only

The length of the path in blocks, from node to node.

nodes: Vec3[ ] — Read-Only

Copies of the positions where the bot stands on its way, in order: the middle of each block it comes through, at the height of that block's bottom. The first is where the bot was when the path was searched, the last is the end of the path.

reachable: boolean — Read-Only

false when the path stops short of the target: the target can't be reached, or it is further away than the search looked.

target: Vec3 — Read-Only

A copy of the position the path was searched to: the last one, if it was searched by way of others.