Villager Tradings

A Villager (previously called a Testificate) is an intelligent passive NPC that the player can trade with. Villagers will not despawn even if the player wanders away from them. There are different types of villagers with random trades.

Behavior
Upon spawning, villagers will leave their homes and begin to explore the village. Generally, they wander aimlessly inside the village during the day. They may go indoors or outdoors. Occasionally, two villagers may stop, and turn to look at each other, in a behavior called socializing, in which they will stare at a mob (sometimes even a zombie) or another villager for a few seconds at a time. In the case of players, they will continuously stare at them as long as the player is close enough, unless the villager tries to get into a house at night or run away from a zombie. When a player attacks a villager, the villager will not run away, but angry particles will fly out from the villager if it is in a village.

Villagers will not willingly fall off high cliffs that would kill them, but may occasionally take fall damage. They will not stay away from fire or cacti, nor change their behavior around them, as with most mobs.

At night, or during a storm, villagers will run inside, closing doors behind them, staying indoors until the morning. In the morning, the villagers will head outside, fleeing from any remaining zombies. Once the zombies are gone, the villagers will resume normal behavior.

There is evidence that villagers are prone to overcrowding certain areas of a village while leaving other areas completely empty. There is speculation that villagers will crowd predictably into set areas; however, exactly which areas has still not been discovered. It has been noticed they crowd their church/watchtower very often at certain times of the day.[1] The overcrowding can lead to villagers swarming into a few houses at night rather than spreading themselves. The sheer amount of villagers trying to enter such a small area can result in a portion of the villagers taking more time to enter the safety of their homes. In extreme cases, some villagers will become stranded outside. There is no known way to prevent this type of overcrowding.

Items
Villagers have eight inventory slots. Villagers will not intentionally seek out items to pick up, but they will collect any bread, carrots, potatoes, wheat, or seeds they happen to come within range of. These are the only items they are able to pick up. If a player and a villager are in the pickup range of an item at the same time, the player will always pick it up first.

Food
If a villager has enough food in one inventory stack (6 bread or 24 carrots or potatoes, or 18 wheat for Farmers only) and sees a villager without enough food in one inventory stack (3 bread or 12 carrots or potatoes for non-Farmers; 15 bread, 60 carrots or potatoes, or 45 wheat for Farmers), he may decide to share food with that villager.

To share, a villager finds his first inventory stack with at least 4 bread, carrots, or potatoes or with at least 6 wheat, and then throws half the stack (rounded down) in the direction of the target villager. When wheat is shared, it is first crafted to bread which may result in 1 or 2 less than half the stack being shared.

Farming
Adult and baby brown-robed villagers, both farmers and other careers, will tend crops within the village boundary. Villagers far enough outside the boundary of any village will also tend nearby crops.

Farmland to be tended is found by seeking for certain blocks up to 15 blocks away from the villager in X and Z and up to 1 away in Y (a 31×31×3 area total).
 * If a brown-robed villager does not have enough food in one stack in his inventory (15 bread, 60 carrots or potatoes, or 45 wheat) and finds fully-grown wheat, carrots, or potatoes, he will move to the crop block and break it.
 * If a brown-robed villager has any seeds, carrots, or potatoes in his inventory and finds an air block above farmland, he will move to it and plant a crop. They will always plant from the first eligible slot in their inventory.

Babies
Baby villagers will sprint around, entering and leaving houses at will. They will also chase each other around the village to simulate that they are playing tag. They will sometimes stop sprinting to stare at an Iron Golem. If the Iron Golem is holding a poppy, the children will cautiously take the flower from its hands.

Unlike other breed-able mobs, the parents and child have no personal interactions other than socializing.

Zombies
Zombies will find villagers from up to 42 block radius (even when the villager is invisible), and will attempt to break down doors. Zombies will only successfully break doors if the difficulty is set to hard; although, only a fraction of zombies spawned in hard mode can break doors. This also applies to zombie pigmen if they path find through a door. Villagers will run away from zombies, which attempt to attack villagers. The villager's only "natural" defense are the Iron Golems, which protect villagers from nearby mobs.

Zombies will kill villagers, or convert them to zombie villagers. The chance that the villager will become a zombie villager on death is 0% on Easy, 50% on Normal, and 100% on Hard. Baby villagers can be infected by zombies as well.

Villagers will also run from zombie pigmen.

Lightning
When lightning strikes between 3-4 blocks of a villager, it will turn into a witch.

Breeding
Villagers will mate depending on the number of valid doors. Villagers will then mate until the number of adult villagers equals or is more than 35% of the number of doors. Any remaining children will grow up as usual, resulting in a total number of adult villagers somewhere above one third of the number of nearby wooden doors. The type of villager that the child is doesn't depend on what type the parents are.

A valid door is any door within the village radius where the number of "outside" spaces within 5 blocks in a straight line on one side of the door is not the same as the number of "outside" spaces within 5 blocks on the other side of the door. A space is considered to be "outside" if it has nothing but transparent blocks above it all the way to the sky.

The game engine periodically takes a census to determine the current population of the village. All villagers within the horizontal boundary of the village and within 5 vertical blocks of the center will be counted as part of the population to determine if continued villager mating is allowed. However, any villager within the horizontal boundary of the village and within a vertical distance of 32 blocks downwards of the center of the village will attempt to enter mating mode as long as there is at least one villager within the boundary. If two villagers simultaneously enter mating mode while they are close to one another, they will mate with each other and produce a child.

Willingness
Additionally, villagers must be "willing" in order to breed. After mating, they will no longer be willing, and must be made willing again.

Villagers may become willing when the player trades with them. Willingness is granted the first time a new offer is traded, or at a one-in-five chance on subsequent trades. Green particles will appear if the villager becomes willing by trading. This will not cause them to immediately seek out a mate, however.

Villagers can also become willing by having either 3 bread, 12 carrots or 12 potatoes in one stack in their inventory. Any villager with an excess of food (usually farmers) will throw food to other villagers, allowing them to pick it up and obtain enough food to become willing. You can also throw bread, carrots, or potatoes at the villagers yourself to encourage breeding. Villagers will consume the required food upon becoming willing.