Mojira Archive
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.