
AI Pathfinder
- 强制自定义实体寻路至世界中的固定位置!(对地图制作非常有用)
- 强制实体追击其他实体!
- 支持版本:1.21.2+
AI Pathfinder 数据包允许你直接为你的自定义生物/怪物/NPC 接入智能寻路功能,适用于地图制作或小游戏。该数据包替你完成了所有繁重的 AI 逻辑——告别那些需要重新建模实体的日子吧!
鸣谢
本数据包基于 CJDev 的 A* Pathfinding 数据包构建!
使用方法
如何使用?
-
首先,选择你的基础实体。
该实体将作为你自定义实体的主体。如果你决定不实现自定义碰撞箱系统,此实体也可作为实体的碰撞箱。如果你使用的是 Minecraft 1.21.9+ 版本,我们建议你选择一个 Mannequin Entity 作为基础实体。
-
其次,将你的实体与自定义实体展示关联起来。
根据你的实现方式,将“自定义实体展示”与此基础实体关联。这可以是一个简单的静态模型,也可以是一个复杂的 Animated-Java Rig。关联可以通过 ID 系统完成,这是该数据包本身未提供的功能。
-
第三,给你的实体添加
ai.pathfinding标签
使用 /tag 命令,赋予你的实体 ai.pathfinding 标签:
/tag <entity> add ai.pathfinding
一旦添加了此标签,该数据包将为 AI 初始化一些基础数值。这些数值包括 AI 的移动速度、状态、跳跃力度、攻击距离、视野范围和视野锥角。
就是这样!一个拥有自定义 AI 且愿意听从你指令的实体诞生了! 接下来是大量可自定义的项目列表:
可修改数值
计分板
ai.State: 存储 AI 的状态。
|__________ Idle (空闲) = 0;
|__________ Walking (行走) = 1;
|__________ Sprinting (疾跑) = 2;
ai.Mode: 存储 AI 的“模式”。
|__________ Idle (空闲) = 0;
|__________ Roaming Only (仅漫游) = 1;
|__________ Chasing Target Entity (追击目标实体) = 2;
时间数值:
ai.PathfindingDuration: 存储 AI 在生成下一条路径之前等待的时间长度。当生成路径时,此值会递减。
ai.ChasingEntityMemoryDuration: 存储 AI 能记住一个实体直到遗忘的时间长度。
ai.baseLostEntityGracePeriod: AI 丢失目标实体后,在开始重新寻路之前等待的时间量。
AI 数值:
ai.baseMovementSpeed: 存储 AI 移动速度的自定义值(根据 ai.State 的值而变化)(x1000)
ai.baseSprintSpeed: 存储 AI 移动速度的自定义值(根据 ai.State 的值而变化)(x1000)
ai.baseJumpStrength: 存储 AI 跳跃力度的自定义值。(x1000)
ai.baseViewAngle: 存储 AI 视野锥角的一半角度 (x1000)
ai.baseViewRange: 存储视野锥角半角的半径 (x1000)
在名称带有 ai.base... 前缀的计分板上设置 AI 的分数是可选的。如果不设置,数据包将使用下面分配的基础值。这些基础值也可以修改,因为它们存储在 ai.Values 计分板中。
基础数值
这些数值在 ai:global/load 中初始化,并经过缩放(x1000)
baseMovementSpeed = 150
baseSprintSpeed = 220
baseJumpStrength = 410
baseViewHalfAngle = 30000 // 60° 锥角。
baseLostEntityGracePeriod = 200 // AI 在重新开始移动前静止不动 10 秒。
// 这些数值经过缩放(x10),因为它们用于射线检测。
baseViewRange = 300 // AI 可以看到最远 30 格远的位置(视野锥角半径为 30 格)
通过修改这些数值,你可以调整 AI 以满足你的需求!
其他示例:
- 假设你想让基础实体只在你想让它运行时才运行。要让它从一个位置移动到另一个位置,将其 ai.State 分数设置为 2。如果只想让它到处走走,将其 ai.State 分数设置为 1。
- 假设你想让你的 AI 实体只漫游而不追击任何实体。将其 ai.Mode 设置为 1。
现在,该数据包提供的 API:
API
"ai:api/pathfind"
用法: execute as <ai> at <location_marker_entity> run function ai:api/pathfind
其他用法: execute as <ai> positioned x y z run function ai:api/pathfind
运行此函数后,AI 将向 <location_marker_entity> 的位置或 (X,Y,Z) 坐标规划一条路径。一旦路径形成,它就开始沿着该路径行进。
"ai:api/set_mode/chasing"
用法: execute as <ai> at @s as <target_entity> run function ai:api/set_mode/chasing
运行此函数后,<target_entity> 将被 AI 锁定为目标。如果 <target_entity> 出现在 AI 的视野锥角内(其尺寸由 ai.ViewRange 和 ai.ViewAngle 计分板指定),AI 将开始追击 <target_entity>。
"ai:api/set_mode/idle"
用法: execute as <ai> run function ai:api/set_mode/idle
此函数停止 AI 执行寻路逻辑。如果你想播放动画,这将非常有用。
"ai:api/set_mode/roaming"
用法: execute as <ai> run function ai:api/set_mode/roaming
运行此函数后,AI 将变得被动。或者,如果存在类型为 #ai:node(默认情况下仅包含 marker)且带有 "ai.Node" 标签的实体,AI 将在随机的时间间隔后随机寻路至这些实体。
标签
AI 实体可能拥有的某些特殊标签,用于修改其行为:
ai.CompletePathBeforeUpdating = AI 可能在到达目的地之前改变路径。此标签可防止这种情况发生。
ai.LookOnlyAtPath = 移动时,AI 只会注视其行进的路径。
ai.RandomlyLookAnywhere = 移动时,AI 会随机看向某个随机的偏航角(Yaw)、俯仰角(Pitch),或附近有趣的实体,旨在增强真实感与生命力。
ai.Node = 类型为 #ai:node 且具有此标签的任何实体都将作为节点,供实体在漫游时前往。有助于修正位置问题。
ai.BeingTargetted = 如果一个具有此标签且在与 AI 实体的记分板 ai.id 中分数相同的实体进入 AI 的视野锥,则当 AI 的 ai.Mode 设置为 2(追逐模式)时,AI 将开始追逐它。
示例
用人体模型重现 Minecraft 玩家!

AI Pathfinder
- Force a Custom Entity to Pathfind to a Fixed Position in the World! (useful for mapmaking)
- Force Entities to Chase Other Entities!
- Supported versions: 1.21.2+
AI Pathfinder datapack allows you to directly plug smart pathfinding to your custom Mob/Monster/NPC for MapMaking or MiniGame purposes. This datapack does all the heavy lifting of the AI for you — Gone are the days of Retexturing Entities!
Credits
This datapack is built upon CJDev's A* Pathfinding datapack!
How to Use
How to Use?
-
First, choose your base entity.
This entity will be the body of your custom entity. This entity may also be the hitbox of your entity, if you decide to not implement a custom hitbox system. If you are on Minecraft Version 1.21.9+, we recommend you choose a Mannequin Entity as your base entity.
-
Second, link your entity with your custom entity display.
Depending on your implementation, link your "custom entity display" with this base entity. This could be something as simple as a static model or as complicated as an Animated-Java Rig. Linking can be done via an ID system that the datapack inherently doesn't provide.
-
Thirdly, give your entity the
ai.pathfindingtag
Using the /tag command, give your entity the ai.pathfinding tag:
/tag <entity> add ai.pathfinding
Once this tag is added, this datapack will initialize some base values for the AI. Values like the MovementSpeed of the AI, the State of the AI, the JumpStrength, the Reach, it's View Range and View Cone.
There you have it! An Entity with custom AI that is willing to listen to your commands! Now, for the big list of customizable things:
Modifyable Values
Scoreboards
ai.State: It stores the State of the AI.
|__________ Idle = 0;
|__________ Walking = 1;
|__________ Sprinting = 2;
ai.Mode: It stores the "Mode" of the AI.
|__________ Idle = 0;
|__________ Roaming Only = 1;
|__________ Chasing Target Entity = 2;
Time Values:
ai.PathfindingDuration: It stores how long the AI waits before creating another path. This value ticks down when a Path is Generated.
ai.ChasingEntityMemoryDuration: It stores the value of how long the AI can remember an entity until it forgets.
ai.baseLostEntityGracePeriod: The amount of time the AI waits after it has lost the target entity, before it begins to pathfind.
AI Values:
ai.baseMovementSpeed: It stores the Custom Value for Movement Speed of the AI (it changes depending on the value of ai.State) (x1000)
ai.baseSprintSpeed: It stores the Custom Value for Movement Speed of the AI (it changes depending on the value of ai.State) (x1000)
ai.baseJumpStrength: It stores the Custom Value for Jump Strength of the AI. (x1000)
ai.baseViewAngle: It stores the half angle of the View Cone of the AI (x1000)
ai.baseViewRange: It stores the Radius of the Half Angle of View Cone (x1000)
Setting the score of the AI on a scoreboard with a name with the ai.base... prefix is optional. Not setting them will result in the datapack using the base values assigned below. These base values can be modified as well, as they're stored in the ai.Values scoreboard.
Base Values
These values are initialized in ai:global/load and are scaled (x1000)
baseMovementSpeed = 150
baseSprintSpeed = 220
baseJumpStrength = 410
baseViewHalfAngle = 30000 // 60° Cone.
baseLostEntityGracePeriod = 200 // AI stands still for 10 seconds before it starts moving again.
// These values are scaled (x10) since they're used in raycasting.
baseViewRange = 300 // AI can see up to 30 blocks away (view cone radius is 30 blocks)
By Modifying these values, you can tune the AI to meet your needs!
Additional Examples:
- Say you wanted to make it so that your base entity only runs when you want it to. To make it run from one location to another, set its ai.State score to 2. If you want it to only walk everywhere, set its ai.State score to 1.
- Say you want your AI entity to only roam but not chase any entity. Set its ai.Mode to 1.
Now, the API that the datapack provides:
API
"ai:api/pathfind"
Usage: execute as <ai> at <location_marker_entity> run function ai:api/pathfind
Usage (other): execute as <ai> positioned x y z run function ai:api/pathfind
Once this function is ran, the AI will formulate a path towards the position of <location_marker_entity> or the (X,Y,Z) coordinate. Once the path is formed, it will begin travelling through it.
"ai:api/set_mode/chasing"
Usage: execute as <ai> at @s as <target_entity> run function ai:api/set_mode/chasing
Once this function is ran, <target_entity> will begin to be targetted by the AI. If <target_entity> appears in the View Cone of the AI, whose dimensions are specified by the ai.ViewRange and ai.ViewAngle scoreboards, the AI will start chasing <target_entity>.
"ai:api/set_mode/idle"
Usage: execute as <ai> run function ai:api/set_mode/idle
This function stops the AI from implementing pathfinding logic. Useful if you want to play an Animation.
"ai:api/set_mode/roaming"
Usage: execute as <ai> run function ai:api/set_mode/roaming
Once this function is ran, the AI will become passive. Alternatively, if there are entities of type #ai:node (by default, it only contains marker) and tag "ai.Node", the AI will randomly pathfind to this entity after random intervals of time.
Tags
Some Special Tags the AI Entity can have that Modify its behavior:
ai.CompletePathBeforeUpdating = There's a possibility that the AI may change path before reaching its destination first. This tag will prevent that from happening.
ai.LookOnlyAtPath = While Moving, The AI will only look at the Path it's travelling.
ai.RandomlyLookAnywhere = While Moving, The AI will Randomly Look either at a Random Yaw, Pitch, or at an interesting nearby entity, meant to heighten Realism and its Life.
ai.Node = Any Entity of Type #ai:node with this tag will act as Node that the entity can travel to while Roaming Around. Useful for fixing Locations.
ai.BeingTargetted = If an Entity with this tag and with the same score as the AI entity in scoreboard ai.id, enters the AI's view cone, the AI will start chasing it IF it's ai.Mode is set to 2 (Chase Mode)
Examples
Recreating the Minecraft Player with Mannequins!
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
下载 AI Pathfinder
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 AI Pathfinder
修复:
- 修复与 26.3 版本的 Predicates 兼容性
- 在 AI.STATE 4 中将高度跳跃替换为实际跳跃
- 修复了 AI 未在请求寻路的精确坐标处停止的问题
修复:
- 修复与 26.3 版本的 Predicates 兼容性
- 在 AI.STATE 4 中将高度跳跃替换为实际跳跃
- 修复了 AI 未在请求寻路的精确坐标处停止的问题
- 已更新以支持 Minecraft 26.3
- 合并了 CJDev 的 Astar v0.7.3
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
添加区块认领和玩家组队功能,并与 Xaero's Minimap 和 World Map 集成

评论 0
登录后参与评分
还没有评论,来抢沙发吧