Class NearestTargetEntitySensor<T extends Entity>

java.lang.Object
cn.nukkit.entity.ai.sensor.NearestTargetEntitySensor<T>
All Implemented Interfaces:
ISensor

@PowerNukkitXOnly @Since("1.19.30-r1") public class NearestTargetEntitySensor<T extends Entity> extends Object implements ISensor
用来搜索最近的目标实体,构造函数中接受一个目标函数Function<T, Boolean> target的Set,用于实体检测,最终结果保存到List<MemoryType<Entity>> memories中.

The constructor accepts a Set of Integer to target function Function<T, Boolean> target to search for the nearest target entity, and the final result is saved to List<MemoryType<Entity>> memories.

  • Field Details

    • minRange

      protected double minRange
    • maxRange

      protected double maxRange
    • period

      protected int period
    • allTargetFunction

      protected Function<T extends Entity,Boolean>[] allTargetFunction
    • memories

      protected List<MemoryType<Entity>> memories
  • Constructor Details

    • NearestTargetEntitySensor

      public NearestTargetEntitySensor(double minRange, double maxRange, List<MemoryType<Entity>> memories)
      不指定目标函数,默认将全部结果存入第一个记忆

      Without specifying the target function, all results will be stored in the first memory by default

      See Also:
    • NearestTargetEntitySensor

      @SafeVarargs public NearestTargetEntitySensor(double minRange, double maxRange, int period, List<MemoryType<Entity>> memories, Function<T,Boolean>... allTargetFunction)
      Parameters:
      minRange - 最小搜索范围
      Minimum Search Range
      maxRange - 最大搜索范围
      Maximum Search Range
      period - 传感器执行周期,单位tick
      Senor execute period
      allTargetFunction - 接收一个Set,将指定目标函数筛选的结果映射到指定索引的记忆上,目标函数接受一个参数T,返回一个Boolean
      Receives a Set that set the results filtered by the specified target function to the memory of the specified index, the target function accepts a parameter T and returns a Boolean
      memories - 保存结果的记忆类型
      Memory class type for saving results
  • Method Details

    • sense

      public void sense(EntityIntelligent entity)
      Specified by:
      sense in interface ISensor
      Parameters:
      entity - 目标实体
    • getPeriod

      public int getPeriod()
      Description copied from interface: ISensor
      返回此传感器的刷新周期,小的刷新周期会使得传感器被更频繁的调用
      Specified by:
      getPeriod in interface ISensor
      Returns:
      刷新周期