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
duplicates 1
Attachments
Comments 11
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?
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
commandVillager 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.
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?