    001    package net.minecraft.world.gen.structure;
    002
    003    import java.util.Arrays;
    004    import java.util.Iterator;
    005    import java.util.List;
    006    import java.util.Map;
    007    import java.util.Random;
    008    import java.util.Map.Entry;
    009    import net.minecraft.util.MathHelper;
    010    import net.minecraft.world.biome.BiomeGenBase;
    011
    012    public class MapGenVillage extends MapGenStructure
    013    {
    014        /** A list of all the biomes villages can spawn in. */
    015        public static List villageSpawnBiomes = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.plains, BiomeGenBase.desert});
    016
    017        /** World terrain type, 0 for normal, 1 for flat map */
    018        private int terrainType;
    019        private int field_82665_g;
    020        private int field_82666_h;
    021
    022        public MapGenVillage()
    023        {
    024            this.terrainType = 0;
    025            this.field_82665_g = 32;
    026            this.field_82666_h = 8;
    027        }
    028
    029        public MapGenVillage(Map par1Map)
    030        {
    031            this();
    032            Iterator var2 = par1Map.entrySet().iterator();
    033
    034            while (var2.hasNext())
    035            {
    036                Entry var3 = (Entry)var2.next();
    037
    038                if (((String)var3.getKey()).equals("size"))
    039                {
    040                    this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)var3.getValue(), this.terrainType, 0);
    041                }
    042                else if (((String)var3.getKey()).equals("distance"))
    043                {
    044                    this.field_82665_g = MathHelper.parseIntWithDefaultAndMax((String)var3.getValue(), this.field_82665_g, this.field_82666_h + 1);
    045                }
    046            }
    047        }
    048
    049        protected boolean canSpawnStructureAtCoords(int par1, int par2)
    050        {
    051            int var3 = par1;
    052            int var4 = par2;
    053
    054            if (par1 < 0)
    055            {
    056                par1 -= this.field_82665_g - 1;
    057            }
    058
    059            if (par2 < 0)
    060            {
    061                par2 -= this.field_82665_g - 1;
    062            }
    063
    064            int var5 = par1 / this.field_82665_g;
    065            int var6 = par2 / this.field_82665_g;
    066            Random var7 = this.worldObj.setRandomSeed(var5, var6, 10387312);
    067            var5 *= this.field_82665_g;
    068            var6 *= this.field_82665_g;
    069            var5 += var7.nextInt(this.field_82665_g - this.field_82666_h);
    070            var6 += var7.nextInt(this.field_82665_g - this.field_82666_h);
    071
    072            if (var3 == var5 && var4 == var6)
    073            {
    074                boolean var8 = this.worldObj.getWorldChunkManager().areBiomesViable(var3 * 16 + 8, var4 * 16 + 8, 0, villageSpawnBiomes);
    075
    076                if (var8)
    077                {
    078                    return true;
    079                }
    080            }
    081
    082            return false;
    083        }
    084
    085        protected StructureStart getStructureStart(int par1, int par2)
    086        {
    087            return new StructureVillageStart(this.worldObj, this.rand, par1, par2, this.terrainType);
    088        }
    089    }