也请为这个项目做出贡献。我没有无限的时间 ?
✅ 功能
- 查找通往目的地的路径的功能
? 用法
调用 astar:_ 函数,并使用其余标记为 astar 的标记来引导任何事物
路径的起始位置将位于当前实体上,而结束位置则是上下文中的当前位置
例如:execute as @s at @p[distance=1..] run function astar:_
请注意,浮动的目的地和未到达的目标会导致失败
建议将 maxCommandChainLength 游戏规则设置为足够高以适应你的地形,或者将路径限制在最多约 10 个方块——否则,一旦达到限制,临时标记可能会残留
配置
配置存储在 astar.config 记分板目标中。
scoreboard players set maxDistance astar.config <maxDistance> — 默认值:100(10 个方块) — 寻路器在最终确定路径之前可以移动的最大距离。
scoreboard players set maxStepHeight astar.config <maxStepHeight> — 默认值:1 — 它可以一次向上行走多少个方块。
scoreboard players set maxFallDistance astar.config -<maxFallDistance> — 默认值:-3 — 负值,它在每一步可以下落多少个方块。
为了避免与其他人的使用冲突,在你的逻辑之前运行 function astar:default_config 或 scoreboard players reset * astar.config
方块标签
#astar:climbable — 可攀爬
#astar:obstructs_floor — 可通行,不可下降
#astar:impassable_floor — 不可通行的地面
#astar:impassable_wall — 不可通行的墙壁
惩罚方块标签
#astar:penalty/damage 160 — 附近
#astar:penalty/danger 80 — 附近
#astar:penalty/disliked 80
你可以向 #astar:eval_node 标签添加一个函数以修改成本 —— return <any> 结果仅使 impassable 生效
— 通过 kill @s 使其不可通行 — 通过 scoreboard players add/remove @s astar.f <amount> 添加/移除成本
惩罚会增加路径段的成本,因此算法倾向于其他路线。
示例代码
#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 my_score 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 # 如果未找到路径,则直接朝目标行走
Please also contribute to this project. I don't have infinite time on my hands ?
✅ Features
- Function to find the path to a destination
? Usage
Call the astar:_ function and use the remaining markers tagged astar to guide anything
The starting position of the path will be located at the current entity, with the end position being the current position in the context
E.g. execute as @s at @p[distance=1..] run function astar:_
Note that floating destinations & unreached targets will result in failure
I recommend setting the maxCommandChainLength gamerule high enough for your terrain, or restrict the path to a maximum of ~10 blocks — otherwise, temporary markers may stay once the limit is reached
Config
The configuration is stored in the astar.config scoreboard objective.
scoreboard players set maxDistance astar.config <maxDistance> — default: 100 (10 blocks) — max distance the pathfinder may travel till finalizing the path.
scoreboard players set maxStepHeight astar.config <maxStepHeight> — default: 1 — how many blocks it may walk up at once.
scoreboard players set maxFallDistance astar.config -<maxFallDistance> — default: -3 — negative value, how many blocks it may fall each step.
To avoid conflicts with others' usage, run function astar:default_config or scoreboard players reset * astar.config before your logic
Block Tags
#astar:climbable — climbable
#astar:obstructs_floor — traversable, no descent
#astar:impassable_floor — impassable floor
#astar:impassable_wall — impassable wall
Penalty Block Tags
#astar:penalty/damage 160 — nearby
#astar:penalty/danger 80 — nearby
#astar:penalty/disliked 80
You may add a function to the #astar:eval_node tag to modify costs — return <any> results in only impassable being effective
— impassable via kill @s — add/remove cost via scoreboard players add/remove @s astar.f <amount>
Penalties increase the cost of a path segment, so the algorithm prefers other routes.
Example code
#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 my_score 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 # Walk directly towards target if no path is found
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 A* Pathfinding
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
提升版本
由于新的数字提供程序,性能更好
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
缓冲的原始输入和线程化的事件轮询
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
查看物品与配方
模组
原版世界生成优化模组
评论 0
登录后参与评分
还没有评论,来抢沙发吧