Package cn.nukkit.entity.ai.sensor
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 Summary
-
Constructor Summary
ConstructorDescriptionNearestTargetEntitySensor
(double minRange, double maxRange, int period, List<MemoryType<Entity>> memories, Function<T, Boolean>... allTargetFunction) NearestTargetEntitySensor
(double minRange, double maxRange, List<MemoryType<Entity>> memories) 不指定目标函数,默认将全部结果存入第一个记忆 -
Method Summary
Modifier and TypeMethodDescriptionint
返回此传感器的刷新周期,小的刷新周期会使得传感器被更频繁的调用void
sense
(EntityIntelligent entity)
-
Field Details
-
minRange
protected double minRange -
maxRange
protected double maxRange -
period
protected int period -
allTargetFunction
-
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
-
NearestTargetEntitySensor
@SafeVarargs public NearestTargetEntitySensor(double minRange, double maxRange, int period, List<MemoryType<Entity>> memories, Function<T, Boolean>... allTargetFunction) - Parameters:
minRange
- 最小搜索范围
Minimum Search RangemaxRange
- 最大搜索范围
Maximum Search Rangeperiod
- 传感器执行周期,单位tick
Senor execute periodallTargetFunction
- 接收一个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 Booleanmemories
- 保存结果的记忆类型
Memory class type for saving results
-
-
Method Details
-
sense
-
getPeriod
public int getPeriod()Description copied from interface:ISensor
返回此传感器的刷新周期,小的刷新周期会使得传感器被更频繁的调用Returns the refresh period of this sensor, a small refresh period will make the sensor be called more frequently
-