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