mojira.dev
MC-102352

All summoned Villagers now break and plant crops

All villagers are breaking and replanting crops. Tested in a creative world with carrots. Did not notice if they were


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

Linked issues

Attachments

Comments 11

Does this apply to villagers from any version, or are these limited to ones from 1.9 (or older), or once spawned vs naturally generated?

I can confirm that it applies to spawned (using spawn eggs in creative) villagers, I will test naturally generated ones and bred ones ASAP. These were all spawned in 16w20a.

After further testing it seems like this only happens for villagers that are summoned with spawn eggs or the /summon command.

Wiki says: "Villagers far enough outside the boundary of any village will also tend nearby crops". Is it WAY?

1 more comments

The enviroment is supposed to only contain pc details.

This issue has been fixed in 1.10.2.

Only affects the villager by command summon(WAI) Monster Spawner spawn in 1.10.2 version.

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.10 using MCP 9.30.

This can happen in the following situations:

  • Villager spawned by spawn egg

  • Villager spawned using the /summon command

  • Villager spawned by special building (such as church defining a Profession value)

  • Profession of farmer villager changed using the /entitydata command

All this situations except the /entitydata one add with a chance of 1/5th the harvest AI to the AIs of the villager. The reason for this is that they call the method net.minecraft.entity.passive.EntityVillager.onInitialSpawn(DifficultyInstance, IEntityLivingData), which picks a random profession but also applies the AI tasks for this profession and after that set the actual profession.

This can be fixed by call this method only if the data of the entity is randomized. This is currently done correctly by the method net.minecraft.tileentity.MobSpawnerBaseLogic.updateSpawner():

if (this.randomEntity.getNbt().getSize() == 1 && this.randomEntity.getNbt().hasKey("id", 8) && entity instanceof EntityLiving)
{
    ((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null);
}

For the /entitydata command the EntityVillager class could override the method net.minecraft.entity.Entity.notifyDataManagerChange(DataParameter<?>) or rather the method net.minecraft.entity.passive.EntityVillager.setProfession(int) if it is guaranteed that this method is always used, and remove the harvest task if the Profession value was 0 before and is now something different and if the harvest task is in the task list.

Command to reproduce

/give @p spawn_egg 1 0 {EntityTag:{id:"Villager",Profession:1,Health:0.1f}}

Tate Daniels

Jens Bergensten

Community Consensus

Minecraft 16w20a, Minecraft 1.10.2

Retrieved