This ensures that negative chunk coordinates are properly floored when divided by the distance; that is, for the default distance of 32 all values between -31 and +31 will round towards 0 since integer division always rounds towards 0 - by subtracting 31 (distance - 1) this ensures that values from -31 to -1 (now -62 to -32) will properly round to -1.
Another way they could have done this, which I implement myself, is to add a large positive number so the modified value is always positive (chunk coordinates will never exceed +/- 1875000 so you only need to add at least 1875000, or 30000000 for block coordinates):
protected boolean canSpawnStructureAtCoords(int chunkX, int chunkZ)
int x = chunkX + this.offsetX;
int z = chunkZ + this.offsetZ;
this.spawnRNG.setChunkSeed(x / this.maxDistance, z / this.maxDistance);
if ((x % this.maxDistance) == this.spawnRNG.nextInt(this.maxDistance - this.minDistance) && (z % this.maxDistance) == this.spawnRNG.nextInt(this.maxDistance - this.minDistance))
public MapGenVillageTMCW(World par1World, int distance, int size)
this.spawnRNG.setSeedModifiers(par1World.getSeed() + 10387312L);
this.offsetX = this.spawnRNG.getOffset();
this.offsetZ = this.spawnRNG.getOffset();
this.maxDistance = distance;
this.villageSize = size;
public int getOffset()
this.state = this.state * 2862933555777941757L + 3037000493L;
return (int)(this.state >>> 34) + 536870912;
Either way, this ensures that there is no discontinuity across the x and z axes (my method also randomizes the offset so that each seed has a different offset; the vanilla method means that each 32x32 chunk region that has a village is always aligned to a multiple of 32 chunks, so villages will only ever generate at a multiple of 32 plus 0 to 23, the random offset added within each region).
That said, do you have an issue with generating villages?