Star_sea233
本帖最后由 Star_sea233 于 2021-8-4 21:45 编辑

如题, 我想弄一个物品, 在玩家使用时 将玩家传送到最近的指定方块。
如何获取到那个离玩家最近的方块坐标?

我有想到过遍历, 但我觉得效率太低且麻烦, 请问应该如何实现

我的环境是: Fabric Minecraft 1.17



洞穴夜莺
Points Of Interest机制了解一下

Star_sea233
本帖最后由 Star_sea233 于 2021-8-4 21:44 编辑
洞穴夜莺 发表于 2021-8-4 20:23
Points Of Interest机制了解一下

嗯, 我百度了一下, 看不太明白。
是不是当玩家对某个方块进行操作时, 记录下周围符合条件的方块位置, 在使用时就直接在记录里面找?

这里问题已经解决了, 感谢大佬, 但我还想多嘴问一问
如果出现了没有被记录过的此类方块呢?

洞穴夜莺
Star_sea233 发表于 2021-8-4 21:40
嗯, 我百度了一下, 看不太明白。
是不是当玩家对某个方块进行操作时, 记录下周围符合条件的方块位置, 在使 ...

Points Of Interest机制是Minecraft村民寻找职业方块的机制,Minecraft存档中的poi.<rx>.<rz>.dat得名于此,你可以看看村民的代码

Star_sea233
洞穴夜莺 发表于 2021-8-4 22:01
Points Of Interest机制是Minecraft村民寻找职业方块的机制,Minecraft存档中的poi...dat得名于此,你可 ...

十分感谢, 我看了下生物 AI, 好多, 不知道在哪找到 工作方块寻路的代码😂

qerw
你可以看看github上baritone的源码
里面有关于寻路功能的
有关于bartione的可以在bilibili上找找

Star_sea233
本帖最后由 Star_sea233 于 2021-8-5 13:18 编辑
qerw 发表于 2021-8-5 08:32
你可以看看github上baritone的源码
里面有关于寻路功能的
有关于bartione的可以在bilibili上找找 ...

感谢回复, 其实我想找到不是寻路实现, 而是如何使用 PointOfInterest 和 PointOfInterestType。
IDEA 里面的查找用法好像不能在反编译代码里面找, 所以找起来困难。
我认为村民寻工作方块和寻路有关, 所以才提到寻路

baritone 的寻找方块的实现应该是遍历周围方块, 也许效率并不是那么好

Star_sea233
本帖最后由 Star_sea233 于 2021-8-5 21:45 编辑

感谢万能的网友和 Fabric, 原来 POI 使用这么简单(之前我一直在生物 AI 里找, 没想到方块更新会触发😂)

部分实现代码:
com.modid.world.poi.LandmarkPOIType:
  1. public class LandmarkPOIType {
  2.     /**
  3.      * 兴趣点方块注册 (个人理解)
  4.      */
  5.     public static final PointOfInterestType Landmark =
  6.             PointOfInterestHelper.register(new Identifier("modid", "landmark"), 0, 1,
  7.                     Blocks.BEACON, Blocks.CONDUIT);

  8.     /**
  9.      * 取得地标数量
  10.      * @return 在 {@param world} 中, 以 {@param radius} 为半径, {@param pos} 为圆心 取得地标数量
  11.      */
  12.     public static long landmarkCount(@NotNull ServerWorld world, @NotNull BlockPos pos, int radius) {
  13.         return world.getPointOfInterestStorage().count(
  14.                 Landmark.getCompletionCondition(), pos, radius, PointOfInterestStorage.OccupationStatus.ANY
  15.         );
  16.     }

  17.     /**
  18.      * 取得最近的地标方块
  19.      * @return 在 {@param world} 中, 以 {@param radius} 为半径, {@param pos} 为圆心 取得最近的地标方块
  20.      */
  21.     public static Optional<BlockPos> getNearest(@NotNull ServerWorld world, BlockPos pos, int radius) {
  22.         return world.getPointOfInterestStorage().getNearestPosition(
  23.                 Landmark.getCompletionCondition(), pos, radius, PointOfInterestStorage.OccupationStatus.ANY
  24.         );
  25.     }
  26. }
复制代码




第一页 上一页 下一页 最后一页