Steps to Reproduce:
Summon a baby turtle via command: /summon minecraft:turtle ~ ~ ~ {Age:-600}
Give turtle resistance V effect to avoid its death via command: /effect give @n[type=minecraft:turtle] minecraft:resistance infinite 4
Summon an ocelot via command: /summon ocelot
Keep feeding the turtle with seagrass to accelerate its growth until it grows up.
Replace ocelot with other (un)tamable mobs to compare the difference, such as wolf, cat, skeleton, etc.
Observed Results: Untamable mobs, such as ocelot and skeleton, keep attacking the turtle, while tamable mobs, such as wolf and cat, stop attacking the turtle.
Expected Results: All mobs should stop attacking the turtle.
Additional information: Although mobs behave differently in Bedrock Edition as well, it doesn't depend on whether its tamable. I'll try to figure it out and create a new ticket in MCPE.
Code analysis:
Mob attacking turtle behavior uses
NearestAttackableTargetGoal
and its subclasses. The behavior can only keep active when the methodcanContinueToUse
returns true.For untamable mobs, they use
NearestAttackableTargetGoal
. They use following method:Untamable mobs don't check the target condition in
canContinueToUse
, so they can't stop attacking immediately when the turtle grows up.For tamable animals, they use
NonTameRandomTargetGoal
. They use following method:Tamable mobs check the target condition in
canContinueToUse
, so they can stop attacking immediately when the turtle grows up.Fix:
Override
canContinueToUse
inNearestAttackableTargetGoal
Remove
canContinueToUse
inNonTameRandomTargetGoal