mojira.dev
MC-198068

Some entities randomly stop attacking or fleeing during pathfinding

The Bug:

Whilst a melee-type mob pursues a player/entity, they may stop attacking once in a while when pathfinding towards their targets. This is also an issue with certain passive mobs as certain passive mobs (e.g. a villager) may randomly stop fleeing for a second if a player hits that entity. (This issue is just like the MCPE counterpart, MCPE-48144).

Affected Entities:

Please note that there may be more entities affected by this issue that aren't listed below.

  • Cave Spider

  • Creeper

  • Enderman

  • Endermite

  • Iron Golem

  • Silverfish

  • Skeleton (without bow)

  • Spider

  • Stray (without bow)

  • Villager

  • Vindicator

  • Wither Skeleton

  • Wolf

  • Zombie

  • Zombie Villager

  • Zombified Piglin

Steps to Reproduce:

  1. Summon any of the affected mobs listed above.

  2. Provoke it if necessary and allow the said entity to attack you.

  3. Observe how sometimes, the entity randomly stops and starts pathfinding even though it hasn't made it to its target.

Observed Behavior:

Entities stop and start pathfinding at random intervals even though they haven't fully approached their target. This happens randomly and can last several seconds before it starts to pathfind again.

Expected Behavior:

Entities would not stop and start pathfinding at random intervals when pursuing their target.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 27

This relates to MC-159299.

anthony cicinelli

Can you upload the video on YouTube as unlisted then post the link her

I've already posted the link in the description. Its too big so it is in the description. Nevermind, trimmed a video.

According to Adrian on MC-147516 it's probably just MC-2310

This is NOT MC-2310. That bug talks about mobs hitting through blocks whilst this talks about mobs stopping pathfinding rnadomly.

17 more comments

@@unknown I updated the title and description to reflect that, thanks.

In 1.20

Can reproduce the bug with Wolves easily

Can confirm in 23w33a

In 1.20.2 Pre-Release 2

After some testing, I determined a slight issue with Chumbanotz's fix: while the followingTargetEvenIfNotSeen check is problematic as it causes a short circuit (since it forces a return statement for all mobs not having this flag set to true), removing the check itself causes the goal not to stop when the entity has reached its target. This is problematic because for a target which doesn't move, there are situations where the mob would create an improper path where it wouldn't be able to reach the entity within its hitting distance, and it would be stuck not being able to attack, virtually causing MC-147516 again. (The details of whether and why this happen is unclear to me though). Rather than removing the check, it would be better to replace it something in the lines of:

...
else if (!followingTargetEvenIfNotSeen && this.mob.getNavigation().isDone()) {
    return false;
}
...

This forces an attacker which has reached its target to properly update its path towards the target as it hits by constantly cancelling and reactivating the goal (but only works properly if the lastCanUseCheck check is removed as the original fix suggested), which is probably what this check was originally intended to do.

user-189af

CallMeChris

(Unassigned)

Confirmed

Platform

Normal

Mob behaviour

pathfinding

1.16.1, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 1, ..., 1.20.5 Pre-Release 1, 1.20.6, 24w19b, 1.21, 1.21.3

Retrieved