AllApplicableBehaviours does not work as expected
Closed this issue · 1 comments
I was trying to use AllApplicableBehaviors
as a way to create a simple sublist of behaviors when adding behaviors to a BehaviorActivityGroup
, expecting all tasks to not only start, but tick as well per the documentation. This was not the case - for example, using BreedWithPartner
as a sub-listed behavior, which ticks continously until breeding is complete, the tick method is never called. This suggests that any instance of AllApplicableBehaviors
is never ticked.
I looked into the source and noticed this in AllApplicableBehaviors#doStartCheck
:
return (this.runningBehaviour = pickBehaviour(level, entity, gameTime, this.behaviours)) != null;
runningBehavior
has to be set to a non-null value for AllApplicableBehaviors#doStartCheck
to return true and tick the running behaviors. However, in AllApplicableBehaviors#pickBehavior
, it always returns null after starting all the behaviors.
My suggestion is to actually return any of the successfully started behaviors in AllApplicableBehaviors#pickBehavior
so that runningBehavior
is set to a non-null value and AllApplicableBehaviors#doStartCheck
can actually return true, allowing the ticking of the started sub behaviors. runningBehavior
is effectively no-op'd per the implementation of AllApplicableBehaviors
so it shouldn't have adverse effects with a set value.
Example:
ExtendedBehaviour<? super E> running = null; for (ExtendedBehaviour<? super E> behaviour : extendedBehaviours) { if(behaviour.tryStart(level, entity, gameTime)){ running = behaviour; } } return running;
Fixed in 1.12.1