-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
n/a
-
1.20.1 build 3867
-
Yes
When an entity which uses the HurtByTargetGoal has their setTarget(null) used, they will immediately re-target their target.
When the canContinueToUse() is run, this.targetMob re-adds the last attacker as the mobs goal.
As an example:
Hit a wolf to cause it to attack you.
Cancel the wolf's damage in the EntityDamageEntityEvent and try to make the wolf docile again using wolf.setAngry(false) or wolf.setTarget(null).
Either setAngry(false) or setTarget(null) will result in a wolf firing a EntityTargetLivingEntity with a null target. (Expected behaviour.)
The wolf however will cause the following to occur as it begins to search for whether it can use its last target after losing their Player target:
at net.minecraft.world.entity.Mob.setTarget(Mob.java:312) ~[?:?] at net.minecraft.world.entity.ai.goal.target.TargetGoal.canContinueToUse(TargetGoal.java:75) ~[?:?] at net.minecraft.world.entity.ai.goal.WrappedGoal.canContinueToUse(WrappedGoal.java:27) ~[?:?] at net.minecraft.world.entity.ai.goal.GoalSelector.tick(GoalSelector.java:109) ~[?:?] at net.minecraft.world.entity.Mob.serverAiStep(Mob.java:920) ~[?:?] at net.minecraft.world.entity.LivingEntity.aiStep(LivingEntity.java:3351) ~[?:?] at net.minecraft.world.entity.Mob.aiStep(Mob.java:673) ~[?:?] at net.minecraft.world.entity.AgeableMob.aiStep(AgeableMob.java:155) ~[?:?] at net.minecraft.world.entity.animal.Animal.aiStep(Animal.java:63) ~[?:?] at net.minecraft.world.entity.animal.Wolf.aiStep(Wolf.java:186) ~[?:?] at net.minecraft.world.entity.LivingEntity.tick(LivingEntity.java:3006) ~[?:?] at net.minecraft.world.entity.Mob.tick(Mob.java:435) ~[?:?] at net.minecraft.world.entity.animal.Wolf.tick(Wolf.java:202) ~[?:?]
with the final Mob.setTarget() causing a new EntityTargetLivingEntityEvent with the original Player as the target.
This target has been set by the canContinueToUse()'s
if (entityliving == null) { entityliving = this.targetMob; }
The end result is that if you're giving a reason to stop the EntityTargetLivingEntityEvent with a event.setTarget(null) or event.setCancelled(true) you will see the entity throw a new EntityTargetLivingEntityEvent about 5 times a second.
Ideally the Mob#setTarget(null) would result in the HurtByTargetGoal being ended or the targetMob being made null and the canContinueToUse() being able to handle a null this.targetMob.