Class Behavior

All Implemented Interfaces:
IBehavior, IBehaviorEvaluator, IBehaviorExecutor

@PowerNukkitXOnly @Since("1.6.0.0-PNX") public class Behavior extends AbstractBehavior
单个的行为对象,包含一个执行器和一个评估器,行为对象委托了它们的方法

A single behavior object, containing an executor and an evaluator, with the behavior object delegating their methods

  • Field Details

    • priority

      protected final int priority
    • weight

      protected final int weight
    • period

      protected final int period
    • executor

      protected IBehaviorExecutor executor
    • evaluator

      protected IBehaviorEvaluator evaluator
  • Constructor Details

  • Method Details

    • evaluate

      public boolean evaluate(EntityIntelligent entity)
      Description copied from interface: IBehaviorEvaluator
      是否需要激活与其绑定的执行器

      这个方法对一个行为只会评估一次,评估通过则开始运行执行器执行行为,直到行为中断或者完成,下一次评估才会开始

      Whether the executor bound to it needs to be activated

      This method evaluates a behavior only once, and if the evaluation passes, the executor execution behavior will start running until the behavior is interrupted or completed, and the next evaluation will not begin

      Parameters:
      entity - 评估目标实体
      Assess the targetEntity
      Returns:
      是否需要激活
      Do you need to activate
    • execute

      public boolean execute(EntityIntelligent entity)
      Description copied from interface: IBehaviorExecutor
      调度器将会持续执行此执行器,直到返回false,或者执行器被中断
      此方法每gt都会调用

      The scheduler will continue to execute this executor until it returns false or the executor is interrupted
      This method will be called every gt

      Parameters:
      entity - 执行目标实体
      Returns:
      boolean
    • onStart

      public void onStart(EntityIntelligent entity)
      Description copied from interface: IBehaviorExecutor
      行为评估成功后,进入激活状态前调用

      After the behavior evaluation is successful, it is called before entering the active state

      Parameters:
      entity - 目标实体
    • onInterrupt

      public void onInterrupt(EntityIntelligent entity)
      Description copied from interface: IBehaviorExecutor
      行为非正常中断时(例如被更高级行为覆盖)调用

      Called when behavior breaks abnormally (e.g. overridden by higher-level behavior)

      Parameters:
      entity - 目标实体
    • onStop

      public void onStop(EntityIntelligent entity)
      Description copied from interface: IBehaviorExecutor
      行为正常结束时(execute()方法返回false)调用

      Called when the behavior ends normally (the execute() method returns false)

      Parameters:
      entity - 目标实体
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPriority

      public int getPriority()
      Description copied from interface: IBehavior
      返回此行为的优先级,高优先级的行为会覆盖低优先级的行为

      Returns the priority of this behavior, with higher-priority behaviors overriding lower-priority ones

      Returns:
      优先级
    • getWeight

      public int getWeight()
      Description copied from interface: IBehavior
      返回此行为的权重值,高权重的行为有更大几率被选中

      Returns the weight value of the behavior, with higher weights having a higher chance of being selected

      Returns:
      权重值
    • getPeriod

      public int getPeriod()
      Description copied from interface: IBehavior
      返回此行为的刷新周期,小的刷新周期会使得评估器被更频繁的调用。注意此方法只会影响评估器的调用,而不会影响执行器的调用。

      Returns the refresh period for this behavior, a small refresh period will cause the evaluator to be called more often. Note that this method only affects evaluator calls, not executor calls.

      Returns:
      刷新周期
      Refresh period
    • getExecutor

      public IBehaviorExecutor getExecutor()
    • getEvaluator

      public IBehaviorEvaluator getEvaluator()