Download A* Pathfinding — Minecraft Mods — MetaMods
A* Pathfinding

A* Pathfinding

Active

Downloads

0

Last update

1 month ago

Versions

24w21a — 1.21.9
Server
Fabric
Forge
Neoforge
Quilt
Libraries
Mobs
Game optimization

A Pathfinding - Intelligent Navigation for Entities

This mod implements the advanced A pathfinding algorithm directly in Minecraft, allowing mobs and other entities to find optimal routes to targets in complex terrain.

Main Features

The system provides a function for calculating routes from the entity's current position to the specified destination. The algorithm considers various types of obstacles and complex terrain.

How to Use

To start pathfinding, call the function astar:. Markers with the astar tag will indicate the calculated route. The starting point is determined by the entity's current position, and the endpoint is determined by the execution context.

Example command: execute as @s at @p[distance=1..] run function astar:

Important: Set the maxCommandChainLength parameter high enough for your terrain or limit the path length to approximately 10 blocks to avoid residual markers when reaching the limit.

Configuration

Configuration is stored in the scoreboard objective astar.config:

  • scoreboard players set maxDistance astar.config <maxDistance> - maximum search distance (default: 100 = 10 blocks)
  • scoreboard players set maxStepHeight astar.config <maxStepHeight> - maximum step height (default: 1)
  • scoreboard players set maxFallDistance astar.config -<maxFallDistance> - maximum fall height per step (negative value, default: -3)

Before use, it's recommended to reset settings: scoreboard players reset * astar.config

Block Tags

The system supports various block categories for precise navigation control:

  • #astar:climbable - climbable blocks
  • #astar:obstructs_floor - traversable blocks without descent
  • #astar:impassable_floor - impassable surfaces
  • #astar:impassable_wall - impassable walls

Penalty Zones

The system accounts for dangerous and undesirable areas through penalty tags:

  • #astar:penalty/damage 160 - damage zones nearby
  • #astar:penalty/danger 80 - dangerous territories
  • #astar:penalty/disliked 80 - undesirable zones

Penalties increase the cost of passing through an area, forcing the algorithm to choose alternative routes.

Advanced Features

You can add your own function to the #astar:eval_node tag to modify path costs. Use kill @s to mark impassable areas or modify costs through scoreboard players add/remove @s astar.f <value>.

Example Implementation

#code:loop.mcfunction:

data modify storage code:pathfinding points append from entity @s Pos
kill @s
execute as @n[type=marker,tag=astar] at @s run function code:loop


#code:main.mcfunction:

execute store success score found myscore at @n[tag=target] if function astar: as @n[type=marker,tag=astar,sort=furthest] at @s run function code:loop
execute unless score found my_score matches 1 run function code:set_direct_target # Direct movement to target if path not found
Project members
CJDev

CJDev

Developer

Created: 15 Sep 2025

ID: 267533