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
标准行为组实现
  • Field Details

    • ROUTE_UPDATE_CYCLE

      protected static int ROUTE_UPDATE_CYCLE
      决定多少gt更新一次路径
    • coreBehaviors

      protected final Set<IBehavior> coreBehaviors
      不会被其他行为覆盖的"核心“行为
    • behaviors

      protected final Set<IBehavior> behaviors
      全部行为
    • sensors

      protected final Set<ISensor> sensors
      传感器
    • controllers

      protected final Set<IController> controllers
      控制器
    • runningCoreBehaviors

      protected final Set<IBehavior> runningCoreBehaviors
      正在运行的”核心“行为
    • runningBehaviors

      protected final Set<IBehavior> runningBehaviors
      正在运行的行为
    • coreBehaviorPeriodTimer

      protected final Map<IBehavior,Integer> coreBehaviorPeriodTimer
      用于存储核心行为距离上次评估逝去的gt数
    • behaviorPeriodTimer

      protected final Map<IBehavior,Integer> behaviorPeriodTimer
      用于存储行为距离上次评估逝去的gt数
    • sensorPeriodTimer

      protected final Map<ISensor,Integer> sensorPeriodTimer
      用于存储传感器距离上次刷新逝去的gt数
    • memoryStorage

      protected final IMemoryStorage memoryStorage
      记忆存储器
    • routeFinder

      protected final SimpleRouteFinder routeFinder
      寻路器(非异步,因为没必要,生物AI本身就是并行的)
    • entity

      protected final EntityIntelligent entity
      此行为组所属实体
    • routeFindingTask

      protected RouteFindingManager.RouteFindingTask routeFindingTask
      寻路任务
    • blockChangeCache

      protected long blockChangeCache
    • currentRouteUpdateTick

      protected int currentRouteUpdateTick
      记录距离上次路径更新过去的gt数
    • forceUpdateRoute

      protected boolean forceUpdateRoute
  • Constructor Details

  • Method Details

    • tickRunningBehaviors

      public void tickRunningBehaviors(EntityIntelligent entity)
      运行并刷新正在运行的行为
      Specified by:
      tickRunningBehaviors in interface IBehaviorGroup
      Parameters:
      entity - 目标实体对象
    • tickRunningCoreBehaviors

      public void tickRunningCoreBehaviors(EntityIntelligent entity)
      Description copied from interface: IBehaviorGroup
      调用行为组内部所有被激活的核心行为IBehavior的执行器IBehaviorExecutor

      Call the executor IBehaviorExecutor of all activated core behavior IBehavior inside the behavior group

      Specified by:
      tickRunningCoreBehaviors in interface IBehaviorGroup
      Parameters:
      entity - 目标实体对象
    • collectSensorData

      public void collectSensorData(EntityIntelligent entity)
      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 storage IMemoryStorage

      Specified by:
      collectSensorData in interface IBehaviorGroup
      Parameters:
      entity - 目标实体对象
    • evaluateCoreBehaviors

      public void evaluateCoreBehaviors(EntityIntelligent entity)
      Description copied from interface: IBehaviorGroup
      调用行为组内部的所有核心行为IBehavior的评估器IBehaviorEvaluator

      Call the evaluator IBehaviorEvaluator of all core behavior IBehavior inside the behavior group

      Specified by:
      evaluateCoreBehaviors in interface IBehaviorGroup
      Parameters:
      entity - 目标实体对象
    • evaluateBehaviors

      public void evaluateBehaviors(EntityIntelligent entity)
      评估所有行为
      Specified by:
      evaluateBehaviors in interface IBehaviorGroup
      Parameters:
      entity - 评估的实体对象
    • applyController

      public void applyController(EntityIntelligent entity)
      Description copied from interface: IBehaviorGroup
      应用行为内部所有的控制器IController

      All controllers inside the application behaviorIController

      Specified by:
      applyController in interface IBehaviorGroup
      Parameters:
      entity - 目标实体对象
    • updateRoute

      public void updateRoute(EntityIntelligent entity)
      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 interface IBehaviorGroup
      Parameters:
      entity - 目标实体
    • shouldUpdateRoute

      @Since("1.19.60-r1") protected boolean shouldUpdateRoute(EntityIntelligent entity)
      检查路径是否需要更新。此方法检测路径经过的ChunkSection是否发生了变化
      Returns:
      是否需要更新路径
    • hasNewUnCalMoveTarget

      protected boolean hasNewUnCalMoveTarget(EntityIntelligent entity)
      通过比对寻路器中设置的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

      public void debugTick(EntityIntelligent entity)
      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 interface IBehaviorGroup
    • calcActiveDelay

      protected int calcActiveDelay(@NotNull EntityIntelligent entity, int originalDelay)
      计算活跃实体延迟
      Parameters:
      entity - 实体
      originalDelay - 原始延迟
      Returns:
      如果实体是非活跃的,则延迟*4,否则返回原始延迟
    • initPeriodTimer

      protected void initPeriodTimer()
    • updateMoveDirection

      protected void updateMoveDirection(EntityIntelligent entity)
    • addToRunningBehaviors

      protected void addToRunningBehaviors(EntityIntelligent entity, @NotNull Set<IBehavior> behaviors)
      添加评估成功后的行为到runningBehaviors
      Parameters:
      entity - 评估的实体
      behaviors - 要添加的行为
    • interruptAllRunningBehaviors

      protected void interruptAllRunningBehaviors(EntityIntelligent entity)
      中断所有正在运行的行为
    • builder

      public static BehaviorGroup.BehaviorGroupBuilder builder()
    • getCoreBehaviors

      public Set<IBehavior> getCoreBehaviors()
      不会被其他行为覆盖的"核心“行为
      Specified by:
      getCoreBehaviors in interface IBehaviorGroup
      Returns:
      行为组包含的核心行为 IBehavior
      Core Behaviors Contained by Behavior Groups IBehavior
    • getBehaviors

      public Set<IBehavior> getBehaviors()
      全部行为
      Specified by:
      getBehaviors in interface IBehaviorGroup
      Returns:
      行为组包含的行为 IBehavior
      Behaviors contained in Behavior Groups IBehavior
    • getSensors

      public Set<ISensor> getSensors()
      传感器
      Specified by:
      getSensors in interface IBehaviorGroup
      Returns:
      行为组包含的传感器 ISensor
      Behavior group includes sensors ISensor
    • getControllers

      public Set<IController> getControllers()
      控制器
      Specified by:
      getControllers in interface IBehaviorGroup
      Returns:
      行为组包含的控制器 IController
      Behavior group contains the controller IController
    • getRunningCoreBehaviors

      public Set<IBehavior> getRunningCoreBehaviors()
      正在运行的”核心“行为
      Specified by:
      getRunningCoreBehaviors in interface IBehaviorGroup
      Returns:
      被激活的核心行为 IBehavior
      Activated Core Behavior IBehavior
    • getRunningBehaviors

      public Set<IBehavior> getRunningBehaviors()
      正在运行的行为
      Specified by:
      getRunningBehaviors in interface IBehaviorGroup
      Returns:
      被激活的行为 IBehavior
      Activated Behavior IBehavior
    • getCoreBehaviorPeriodTimer

      public Map<IBehavior,Integer> getCoreBehaviorPeriodTimer()
      用于存储核心行为距离上次评估逝去的gt数
    • getBehaviorPeriodTimer

      public Map<IBehavior,Integer> getBehaviorPeriodTimer()
      用于存储行为距离上次评估逝去的gt数
    • getSensorPeriodTimer

      public Map<ISensor,Integer> getSensorPeriodTimer()
      用于存储传感器距离上次刷新逝去的gt数
    • getMemoryStorage

      public IMemoryStorage getMemoryStorage()
      记忆存储器
      Specified by:
      getMemoryStorage in interface IBehaviorGroup
      Returns:
      行为组的记忆存储器 IMemoryStorage
      Behavior Group Memory Storage IMemoryStorage
    • getRouteFinder

      public SimpleRouteFinder getRouteFinder()
      寻路器(非异步,因为没必要,生物AI本身就是并行的)
      Specified by:
      getRouteFinder in interface IBehaviorGroup
      Returns:
      行为组使用的寻路器 IRouteFinder
      Routefinder used by behavior groups IRouteFinder
    • getEntity

      public EntityIntelligent getEntity()
      此行为组所属实体
    • getRouteFindingTask

      public RouteFindingManager.RouteFindingTask getRouteFindingTask()
      寻路任务
    • getBlockChangeCache

      public long getBlockChangeCache()
    • getCurrentRouteUpdateTick

      public int getCurrentRouteUpdateTick()
      记录距离上次路径更新过去的gt数
    • isForceUpdateRoute

      public boolean isForceUpdateRoute()
      Specified by:
      isForceUpdateRoute in interface IBehaviorGroup
      Returns:
      下一gt是否强制更新路径
      Whether the next gt is forced to update the path
    • setRouteFindingTask

      public void setRouteFindingTask(RouteFindingManager.RouteFindingTask routeFindingTask)
      寻路任务
    • 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 interface IBehaviorGroup
      Parameters:
      forceUpdateRoute - 立即更新路径