mojira.dev
MC-121175

Villager run from zombies too slowly/have inconsistent running speeds

The bug

When running to get into houses during nightfall, villagers run extremely fast. However when escaping from zombies (including babies), they only walk at normal speeds, allowing zombies (especially babies) to catch up and kill them. They run from illagers faster than from zombies, but not as fast as getting into houses.

This running behavior is incorrect; if anything they should sprint away from zombies and vindicators, and walk normally to get into houses (where there's no real danger). Their sprinting to get into houses also impairs their ability to get through the doorway.

How to reproduce

Summon a NoAI zombie and vindicator at opposite ends of a 10-15 block long tunnel, and spawn a villager. It will sprint away from the vindicator to the zombie, than walk away from the zombie back to the vindicator.

Videos demonstrating the issue

Note that the first video was taken during daytime, and the latter two were during nighttime with the Night Vision effect.

Code analysis

This was decompiled in 1.12 with MCP 9.40:

The different villager "running" actions were given different speeds (which may be intended, but is inconsistent). The file EntityVillager.java has the following four lines in the initEntityAI() method:

this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));

this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D));

this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D));

this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D));

In the file EntityAIMoveIndoors.java, there is the following line of code:

this.entity.getNavigator().tryMoveToXYZ((double)i + 0.5D, (double)j, (double)k + 0.5D, 1.0D);

It seems like the speed modifiers of Villagers are set to 0.6 for avoiding zombies, 0.8 for illagers, and 1.0 for moving indoors. This priority is incorrect; villagers should move faster when avoiding actual zombies instead of moving indoors due to supposed threats.

Comments

marcono1234

It looks like this is fixed, but it would be good if someone else can confirm this.

In 1.15 villagers do not have AI tasks, but instead activities. It appears the activities in question are returned by

  • VillagerGoalPackages.getRestPackage(VillagerProfession, float): Walks to home with a speed of f

  • VillagerGoalPackages.getHidePackage(VillagerProfession, float): Walks to home with a speed of f * 1.25

  • VillagerGoalPackages.getPanicPackage(VillagerProfession, float): Walks away from monsters or mobs which hurt the villager with a speed of f * 1.5

Sonicwave

Resolving as Cannot Reproduce since I can no longer reproduce this (at least in 1.15); also see Marcono's comment.

Sonicwave

(Unassigned)

Confirmed

(Unassigned)

ai, movementSpeed, speed, villager, zombie

Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 17w43a, Minecraft 17w43b, Minecraft 17w45a, ..., Minecraft 18w43b, Minecraft 18w43c, Minecraft 18w44a, Minecraft 18w45a, Minecraft 18w50a

Retrieved