Star

A* Pathfinding algorithm implementation

API / Library

Download (18 KB)
For Luanti 5.13 and above

How do I install this?

The A* algorithm is a pathfinding algorithm: it can be used to search for paths between points in a graph. This mod provides a pathfinding function that can be used to perform such searches in the voxel-based fame world of Luanti. It can be used, for instance, for mob AI.

The intent of this mod is to provide a better alternative for Luanti's built-in pathfinder core.find_path. Although the built-in pathfinder is fast, it lacks various useful features, such as the ability to work with mobs larger than 1x1 nodes. Therefore, this implementation allows specifying width and height and comes with various other improvements.

These improvements are not completely free, and searches will take longer: (on my machine, CPU: Ryzen 5) the built-in core.find_path often takes far less than 1 ms to produce a path. In contrast, it is rare (again, on my machine) for star.find_path to take less than 1 ms. However, the performance is, in my opinion, acceptable after several runs. Maybe LuaJIT somehow optimizes it?

Current status:

  • Entity size works
  • Avoiding danger (lava, etc.) works
  • Climbing ladders works
  • Diagonal movement works?

Testing tool disabled starting from 2026-01-18.

API 🔗

star.find_path(pos1, pos2, settings) 🔗

Returns a path as a flat array (from end to start): {x1, y1, z1, x2, y2, z2, ...}

Arguments:

  • pos1, pos2: {x = ..., y = ..., z = ...}
    • pos1 is the starting position and pos2 the target position.
  • settings: {height = ..., etc.}

Settings (values must be positive natural numbers):

  • width: Specifies the object size along x- and z-axes. Defaults to 1.
  • height: Specifies the object size along the y-axis. Defaults to 2.
  • max_jump: Specifies the maximum jump height. Defaults to 1.
  • max_drop: Specifies the maximum drop height. Defaults to 1.
  • max_iter: Specifies the maximum number of main loop iterations before quitting. Defaults to 256. For now, has a hard limit of 1024.
  • climb: Sets the ability to climb ladders (true or false). Defaults to false.

TODO:

  • Weighted terrain
  • Sometimes behaves weirdly???

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.