Class BehaviorGroup
java.lang.Object
cn.nukkit.entity.ai.behaviorgroup.BehaviorGroup
- All Implemented Interfaces:
IBehaviorGroup
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class BehaviorGroup
extends Object
implements IBehaviorGroup
标准行为组实现
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
protected static final record
描述一个ChunkSection的位置 -
Field Summary
Modifier and TypeFieldDescription用于存储行为距离上次评估逝去的gt数全部行为protected long
protected final Set<IController>
控制器用于存储核心行为距离上次评估逝去的gt数不会被其他行为覆盖的"核心“行为protected int
记录距离上次路径更新过去的gt数protected final EntityIntelligent
此行为组所属实体protected boolean
protected final IMemoryStorage
记忆存储器protected static int
决定多少gt更新一次路径protected final SimpleRouteFinder
寻路器(非异步,因为没必要,生物AI本身就是并行的)protected RouteFindingManager.RouteFindingTask
寻路任务正在运行的行为正在运行的”核心“行为用于存储传感器距离上次刷新逝去的gt数传感器 -
Constructor Summary
ConstructorDescriptionBehaviorGroup
(int startRouteUpdateTick, Set<IBehavior> coreBehaviors, Set<IBehavior> behaviors, Set<ISensor> sensors, Set<IController> controllers, SimpleRouteFinder routeFinder, EntityIntelligent entity) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToRunningBehaviors
(EntityIntelligent entity, Set<IBehavior> behaviors) 添加评估成功后的行为到runningBehaviors
void
applyController
(EntityIntelligent entity) 应用行为内部所有的控制器IController
builder()
protected void
cacheSectionBlockChange
(Level level, Set<BehaviorGroup.ChunkSectionVector> vecs) 缓存section的blockChanges到blockChangeCacheprotected int
calcActiveDelay
(EntityIntelligent entity, int originalDelay) 计算活跃实体延迟protected Set<BehaviorGroup.ChunkSectionVector>
calPassByChunkSections
(Collection<Vector3> nodes, Level level) 计算坐标集经过的ChunkSectionvoid
collectSensorData
(EntityIntelligent entity) 调用行为组内部的所有传感器ISensor
,并将传感器返回的记忆数据写入到记忆存储器中IMemoryStorage
void
debugTick
(EntityIntelligent entity) 当 EntityAI.checkDebugOption(BEHAVIOR) == true 时此方法每1gt调用一次,用于debug模式相关内容的刷新void
evaluateBehaviors
(EntityIntelligent entity) 评估所有行为void
调用行为组内部的所有核心行为IBehavior
的评估器IBehaviorEvaluator
用于存储行为距离上次评估逝去的gt数全部行为long
控制器用于存储核心行为距离上次评估逝去的gt数不会被其他行为覆盖的"核心“行为int
记录距离上次路径更新过去的gt数此行为组所属实体记忆存储器寻路器(非异步,因为没必要,生物AI本身就是并行的)寻路任务正在运行的行为正在运行的”核心“行为protected long
getSectionBlockChange
(Level level, BehaviorGroup.ChunkSectionVector vector) 返回sectionVector对应的section的blockChanges用于存储传感器距离上次刷新逝去的gt数传感器protected boolean
通过比对寻路器中设置的moveTarget与entity的moveTarget来确认实体是否设置了新的未计算的moveTargetprotected void
protected void
中断所有正在运行的行为boolean
void
setBlockChangeCache
(long blockChangeCache) void
setCurrentRouteUpdateTick
(int currentRouteUpdateTick) 记录距离上次路径更新过去的gt数void
setForceUpdateRoute
(boolean forceUpdateRoute) 要求下一gt立即更新路径void
setRouteFindingTask
(RouteFindingManager.RouteFindingTask routeFindingTask) 寻路任务protected boolean
shouldUpdateRoute
(EntityIntelligent entity) 检查路径是否需要更新。此方法检测路径经过的ChunkSection是否发生了变化void
运行并刷新正在运行的行为void
调用行为组内部所有被激活的核心行为IBehavior
的执行器IBehaviorExecutor
protected void
updateMoveDirection
(EntityIntelligent entity) void
updateRoute
(EntityIntelligent entity) 通过行为组使用的寻路器更新当前位置到目标位置路径Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface cn.nukkit.entity.ai.behaviorgroup.IBehaviorGroup
save
-
Field Details
-
ROUTE_UPDATE_CYCLE
protected static int ROUTE_UPDATE_CYCLE决定多少gt更新一次路径 -
coreBehaviors
不会被其他行为覆盖的"核心“行为 -
behaviors
全部行为 -
sensors
传感器 -
controllers
控制器 -
runningCoreBehaviors
正在运行的”核心“行为 -
runningBehaviors
正在运行的行为 -
coreBehaviorPeriodTimer
用于存储核心行为距离上次评估逝去的gt数 -
behaviorPeriodTimer
用于存储行为距离上次评估逝去的gt数 -
sensorPeriodTimer
用于存储传感器距离上次刷新逝去的gt数 -
memoryStorage
记忆存储器 -
routeFinder
寻路器(非异步,因为没必要,生物AI本身就是并行的) -
entity
此行为组所属实体 -
routeFindingTask
寻路任务 -
blockChangeCache
protected long blockChangeCache -
currentRouteUpdateTick
protected int currentRouteUpdateTick记录距离上次路径更新过去的gt数 -
forceUpdateRoute
protected boolean forceUpdateRoute
-
-
Constructor Details
-
BehaviorGroup
public BehaviorGroup(int startRouteUpdateTick, Set<IBehavior> coreBehaviors, Set<IBehavior> behaviors, Set<ISensor> sensors, Set<IController> controllers, SimpleRouteFinder routeFinder, EntityIntelligent entity)
-
-
Method Details
-
tickRunningBehaviors
运行并刷新正在运行的行为- Specified by:
tickRunningBehaviors
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体对象
-
tickRunningCoreBehaviors
Description copied from interface:IBehaviorGroup
调用行为组内部所有被激活的核心行为IBehavior
的执行器IBehaviorExecutor
Call the executor
IBehaviorExecutor
of all activated core behaviorIBehavior
inside the behavior group- Specified by:
tickRunningCoreBehaviors
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体对象
-
collectSensorData
Description copied from interface:IBehaviorGroup
调用行为组内部的所有传感器ISensor
,并将传感器返回的记忆数据写入到记忆存储器中IMemoryStorage
Call all sensors
ISensor
inside the behavior group, and write the memory data returned by the sensor to the memory storageIMemoryStorage
- Specified by:
collectSensorData
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体对象
-
evaluateCoreBehaviors
Description copied from interface:IBehaviorGroup
调用行为组内部的所有核心行为IBehavior
的评估器IBehaviorEvaluator
Call the evaluator
IBehaviorEvaluator
of all core behaviorIBehavior
inside the behavior group- Specified by:
evaluateCoreBehaviors
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体对象
-
evaluateBehaviors
评估所有行为- Specified by:
evaluateBehaviors
in interfaceIBehaviorGroup
- Parameters:
entity
- 评估的实体对象
-
applyController
Description copied from interface:IBehaviorGroup
应用行为内部所有的控制器IController
All controllers inside the application behavior
IController
- Specified by:
applyController
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体对象
-
updateRoute
Description copied from interface:IBehaviorGroup
通过行为组使用的寻路器更新当前位置到目标位置路径Update the path from the current position to the target position through the pathfinder used by the behavior group
- Specified by:
updateRoute
in interfaceIBehaviorGroup
- Parameters:
entity
- 目标实体
-
shouldUpdateRoute
检查路径是否需要更新。此方法检测路径经过的ChunkSection是否发生了变化- Returns:
- 是否需要更新路径
-
hasNewUnCalMoveTarget
通过比对寻路器中设置的moveTarget与entity的moveTarget来确认实体是否设置了新的未计算的moveTarget- Parameters:
entity
- 实体- Returns:
- 是否存在新的未计算的寻路目标
-
cacheSectionBlockChange
@Since("1.19.60-r1") protected void cacheSectionBlockChange(Level level, Set<BehaviorGroup.ChunkSectionVector> vecs) 缓存section的blockChanges到blockChangeCache -
getSectionBlockChange
@Since("1.19.60-r1") protected long getSectionBlockChange(Level level, BehaviorGroup.ChunkSectionVector vector) 返回sectionVector对应的section的blockChanges -
calPassByChunkSections
@Since("1.19.60-r1") protected Set<BehaviorGroup.ChunkSectionVector> calPassByChunkSections(Collection<Vector3> nodes, Level level) 计算坐标集经过的ChunkSection- Returns:
- (chunkX | chunkSectionY | chunkZ)
-
debugTick
Description copied from interface:IBehaviorGroup
当 EntityAI.checkDebugOption(BEHAVIOR) == true 时此方法每1gt调用一次,用于debug模式相关内容的刷新When EntityAI.checkDebugOption(BEHAVIOR) == true, this method is called every 1gt to refresh the content related to debug mode
- Specified by:
debugTick
in interfaceIBehaviorGroup
-
calcActiveDelay
计算活跃实体延迟- Parameters:
entity
- 实体originalDelay
- 原始延迟- Returns:
- 如果实体是非活跃的,则延迟*4,否则返回原始延迟
-
initPeriodTimer
protected void initPeriodTimer() -
updateMoveDirection
-
addToRunningBehaviors
添加评估成功后的行为到runningBehaviors
- Parameters:
entity
- 评估的实体behaviors
- 要添加的行为
-
interruptAllRunningBehaviors
中断所有正在运行的行为 -
builder
-
getCoreBehaviors
不会被其他行为覆盖的"核心“行为- Specified by:
getCoreBehaviors
in interfaceIBehaviorGroup
- Returns:
- 行为组包含的核心行为
IBehavior
Core Behaviors Contained by Behavior GroupsIBehavior
-
getBehaviors
全部行为- Specified by:
getBehaviors
in interfaceIBehaviorGroup
- Returns:
- 行为组包含的行为
IBehavior
Behaviors contained in Behavior GroupsIBehavior
-
getSensors
传感器- Specified by:
getSensors
in interfaceIBehaviorGroup
- Returns:
- 行为组包含的传感器
ISensor
Behavior group includes sensorsISensor
-
getControllers
控制器- Specified by:
getControllers
in interfaceIBehaviorGroup
- Returns:
- 行为组包含的控制器
IController
Behavior group contains the controllerIController
-
getRunningCoreBehaviors
正在运行的”核心“行为- Specified by:
getRunningCoreBehaviors
in interfaceIBehaviorGroup
- Returns:
- 被激活的核心行为
IBehavior
Activated Core BehaviorIBehavior
-
getRunningBehaviors
正在运行的行为- Specified by:
getRunningBehaviors
in interfaceIBehaviorGroup
- Returns:
- 被激活的行为
IBehavior
Activated BehaviorIBehavior
-
getCoreBehaviorPeriodTimer
用于存储核心行为距离上次评估逝去的gt数 -
getBehaviorPeriodTimer
用于存储行为距离上次评估逝去的gt数 -
getSensorPeriodTimer
用于存储传感器距离上次刷新逝去的gt数 -
getMemoryStorage
记忆存储器- Specified by:
getMemoryStorage
in interfaceIBehaviorGroup
- Returns:
- 行为组的记忆存储器
IMemoryStorage
Behavior Group Memory StorageIMemoryStorage
-
getRouteFinder
寻路器(非异步,因为没必要,生物AI本身就是并行的)- Specified by:
getRouteFinder
in interfaceIBehaviorGroup
- Returns:
- 行为组使用的寻路器
IRouteFinder
Routefinder used by behavior groupsIRouteFinder
-
getEntity
此行为组所属实体 -
getRouteFindingTask
寻路任务 -
getBlockChangeCache
public long getBlockChangeCache() -
getCurrentRouteUpdateTick
public int getCurrentRouteUpdateTick()记录距离上次路径更新过去的gt数 -
isForceUpdateRoute
public boolean isForceUpdateRoute()- Specified by:
isForceUpdateRoute
in interfaceIBehaviorGroup
- Returns:
- 下一gt是否强制更新路径
Whether the next gt is forced to update the path
-
setRouteFindingTask
寻路任务 -
setBlockChangeCache
public void setBlockChangeCache(long blockChangeCache) -
setCurrentRouteUpdateTick
public void setCurrentRouteUpdateTick(int currentRouteUpdateTick) 记录距离上次路径更新过去的gt数 -
setForceUpdateRoute
public void setForceUpdateRoute(boolean forceUpdateRoute) Description copied from interface:IBehaviorGroup
要求下一gt立即更新路径Ask the next gt to update the path immediately
- Specified by:
setForceUpdateRoute
in interfaceIBehaviorGroup
- Parameters:
forceUpdateRoute
- 立即更新路径
-