001package net.minecraft.world.gen.structure;
002
003import java.util.Arrays;
004import java.util.Iterator;
005import java.util.List;
006import java.util.Map;
007import java.util.Random;
008import java.util.Map.Entry;
009import net.minecraft.util.MathHelper;
010import net.minecraft.world.biome.BiomeGenBase;
011
012public 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 iterator = par1Map.entrySet().iterator();
033
034        while (iterator.hasNext())
035        {
036            Entry entry = (Entry)iterator.next();
037
038            if (((String)entry.getKey()).equals("size"))
039            {
040                this.terrainType = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.terrainType, 0);
041            }
042            else if (((String)entry.getKey()).equals("distance"))
043            {
044                this.field_82665_g = MathHelper.parseIntWithDefaultAndMax((String)entry.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 k = par1;
052        int l = 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 i1 = par1 / this.field_82665_g;
065        int j1 = par2 / this.field_82665_g;
066        Random random = this.worldObj.setRandomSeed(i1, j1, 10387312);
067        i1 *= this.field_82665_g;
068        j1 *= this.field_82665_g;
069        i1 += random.nextInt(this.field_82665_g - this.field_82666_h);
070        j1 += random.nextInt(this.field_82665_g - this.field_82666_h);
071
072        if (k == i1 && l == j1)
073        {
074            boolean flag = this.worldObj.getWorldChunkManager().areBiomesViable(k * 16 + 8, l * 16 + 8, 0, villageSpawnBiomes);
075
076            if (flag)
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}