3

On the initial generation (before any player interactions, and not repopulation) of a village, what determines where the villagers will spawn? Will they spawn inside houses within a radius of the center? Or outside on the gravel paths/farms?.

5

During generation, a structure has the option to run the following function:

protected void spawnVillagers(World worldIn, StructureBoundingBox sbb, int X, int Y, int Z, int maxVillagers)
{
    if (this.villagersSpawned < maxVillagers)
    {
        for (int i = this.villagersSpawned; i < maxVillagers; ++i)
        {
            int xOffset = this.getXWithOffset(X + i, Z);
            int yOffset = this.getYWithOffset(Y);
            int zOffset = this.getZWithOffset(X + i, Z);

            if (!sbb.isVecInside(new BlockPos(xOffset, yOffset, zOffset)))
            {
                break;
            }

            ++this.villagersSpawned;
            EntityVillager entityvillager = new EntityVillager(worldIn);
            entityvillager.setLocationAndAngles(xOffset + 0.5D, yOffset, zOffset + 0.5D, 0.0F, 0.0F);
            entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null);
            entityvillager.setProfession(this.func_180779_c(i, entityvillager.getProfession()));
            worldIn.spawnEntityInWorld(entityvillager);
        }
    }
}

As long as the number villagers spawned for this individual structure is less than the maximum input, it will attempt to spawn a villager at the specified coordinates (which are initially relative to the corner of the structure's bounding box) provided it's not inside a block. To reiterate: the villagersSpawned is not for the entire village, but for this individually-spawned structure.

An example of the function being called, which is used by the "church" structure:

this.spawnVillagers(worldIn, structureBoundingBoxIn, 2, 1, 2, 1);

The maximum number of villagers to spawn inside a church is 1 and will always spawn at the provided offset coordinates.

Out of all the structures available, only large and small farms do not use this function.

Here are images where villagers will always spawn, represented by armor stands (though rotation of the structure may cause them to be mirrored on the other side).

Overview

Here is an example village where villager spawns are highlighted (armor stands with the Glowing effect):

Entire village with glowing armor stands

Church

Church

Wood Hut

Wood hut

Large House

Large House

Butcher's Shop

Butcher's Shop

Library

Library

Small House

Small House

Blacksmith

Blacksmith

2

The Wiki says,

"Villagers spawn along with naturally-generated villages, inside various buildings."

So we can assume that they are in fact spawned inside the surrounding buildings of the village, and then exit.

Again hitting up the Wiki it says that,

"There is evidence that villagers are prone to overcrowding certain areas of a village while leaving other areas completely empty. When moving inside, the AI prefers doors within 16 blocks (Euclidean distance). It also attempts to prefer doors with fewer villagers nearby, however "nearby" in this case is only 1.5 blocks and, when moving inside, villagers prefer to move 2.5 blocks inside when the inside is to the south or east and therefore will be out of range of this check. During the day, it has been observed that villagers will tend to cluster near a trapped villager or any existing large cluster of villagers, likely due to the "socialize" AI routine overriding their inclination to wander".

Seeing as the AI clump together within a shorter radius, they likely spawn as a group, and then spread out initially during the day, moving to different areas as they travel throughout the day, and return to their various homes come nightfall.

  • For some reason, if I spawn right next to a village, there will usually be villagers all around the place, tending to crops and whatnot, so it seems to as if their spawning is not restricted to interiors (or maybe they spawn inside the buildings, then run through an accelerated day/night cycle?). Does anyone have some code excerpts? – EWC May 8 '16 at 8:26
  • Also, I'm pretty sure the clumping up thing has to deal with where the calculated center of the village is, meaning their clustering has little to do with where they span, but what village their in. If I sweep back and forth with the spawn eggs in a existing village (which I've done) they just pile with the rest of the existing villagers. – EWC May 8 '16 at 8:33
  • Do you think using /summon Villager ~ ~ ~ (command to summon a villager) would be efficient to see how they spawn? Or does that just spawn the villager to the player? – Izayuh May 8 '16 at 8:35
  • @Bearded-Ben That command would spawn a villager at the player, rather than a village. – angussidney May 8 '16 at 8:36
  • I was looking for the initial generation of villagers, not player manipulated ones – EWC May 8 '16 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.