    001package net.minecraft.world.gen.structure;
    002
    003import java.util.ArrayList;
    004import java.util.Arrays;
    005import java.util.Collections;
    006import java.util.Iterator;
    007import java.util.List;
    008import java.util.Map;
    009import java.util.Random;
    010import java.util.Map.Entry;
    011import net.minecraft.util.MathHelper;
    012import net.minecraft.world.ChunkCoordIntPair;
    013import net.minecraft.world.ChunkPosition;
    014import net.minecraft.world.biome.BiomeGenBase;
    015
    016public class MapGenStronghold extends MapGenStructure
    017{
    018    public static ArrayList<BiomeGenBase> allowedBiomes = new ArrayList<BiomeGenBase>(Arrays.asList(BiomeGenBase.desert, BiomeGenBase.forest, BiomeGenBase.extremeHills, BiomeGenBase.swampland, BiomeGenBase.taiga, BiomeGenBase.icePlains, BiomeGenBase.iceMountains, BiomeGenBase.desertHills, BiomeGenBase.forestHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.jungle, BiomeGenBase.jungleHills));
    019    private BiomeGenBase[] allowedBiomeGenBases;
    020
    021    /**
    022     * is spawned false and set true once the defined BiomeGenBases were compared with the present ones
    023     */
    024    private boolean ranBiomeCheck;
    025    private ChunkCoordIntPair[] structureCoords;
    026    private double field_82671_h;
    027    private int field_82672_i;
    028
    029    public MapGenStronghold()
    030    {
    031        this.allowedBiomeGenBases = allowedBiomes.toArray(new BiomeGenBase[0]);
    032        this.structureCoords = new ChunkCoordIntPair[3];
    033        this.field_82671_h = 32.0D;
    034        this.field_82672_i = 3;
    035    }
    036
    037    public MapGenStronghold(Map par1Map)
    038    {
    039        this.allowedBiomeGenBases = allowedBiomes.toArray(new BiomeGenBase[0]);
    040        this.structureCoords = new ChunkCoordIntPair[3];
    041        this.field_82671_h = 32.0D;
    042        this.field_82672_i = 3;
    043        Iterator iterator = par1Map.entrySet().iterator();
    044
    045        while (iterator.hasNext())
    046        {
    047            Entry entry = (Entry)iterator.next();
    048
    049            if (((String)entry.getKey()).equals("distance"))
    050            {
    051                this.field_82671_h = MathHelper.func_82713_a((String)entry.getValue(), this.field_82671_h, 1.0D);
    052            }
    053            else if (((String)entry.getKey()).equals("count"))
    054            {
    055                this.structureCoords = new ChunkCoordIntPair[MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.structureCoords.length, 1)];
    056            }
    057            else if (((String)entry.getKey()).equals("spread"))
    058            {
    059                this.field_82672_i = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.field_82672_i, 1);
    060            }
    061        }
    062    }
    063
    064    protected boolean canSpawnStructureAtCoords(int par1, int par2)
    065    {
    066        if (!this.ranBiomeCheck)
    067        {
    068            Random random = new Random();
    069            random.setSeed(this.worldObj.getSeed());
    070            double d0 = random.nextDouble() * Math.PI * 2.0D;
    071            int k = 1;
    072
    073            for (int l = 0; l < this.structureCoords.length; ++l)
    074            {
    075                double d1 = (1.25D * (double)k + random.nextDouble()) * this.field_82671_h * (double)k;
    076                int i1 = (int)Math.round(Math.cos(d0) * d1);
    077                int j1 = (int)Math.round(Math.sin(d0) * d1);
    078                ArrayList arraylist = new ArrayList();
    079                Collections.addAll(arraylist, this.allowedBiomeGenBases);
    080                ChunkPosition chunkposition = this.worldObj.getWorldChunkManager().findBiomePosition((i1 << 4) + 8, (j1 << 4) + 8, 112, arraylist, random);
    081
    082                if (chunkposition != null)
    083                {
    084                    i1 = chunkposition.x >> 4;
    085                    j1 = chunkposition.z >> 4;
    086                }
    087
    088                this.structureCoords[l] = new ChunkCoordIntPair(i1, j1);
    089                d0 += (Math.PI * 2D) * (double)k / (double)this.field_82672_i;
    090
    091                if (l == this.field_82672_i)
    092                {
    093                    k += 2 + random.nextInt(5);
    094                    this.field_82672_i += 1 + random.nextInt(2);
    095                }
    096            }
    097
    098            this.ranBiomeCheck = true;
    099        }
    100
    101        ChunkCoordIntPair[] achunkcoordintpair = this.structureCoords;
    102        int k1 = achunkcoordintpair.length;
    103
    104        for (int l1 = 0; l1 < k1; ++l1)
    105        {
    106            ChunkCoordIntPair chunkcoordintpair = achunkcoordintpair[l1];
    107
    108            if (par1 == chunkcoordintpair.chunkXPos && par2 == chunkcoordintpair.chunkZPos)
    109            {
    110                return true;
    111            }
    112        }
    113
    114        return false;
    115    }
    116
    117    /**
    118     * Returns a list of other locations at which the structure generation has been run, or null if not relevant to this
    119     * structure generator.
    120     */
    121    protected List getCoordList()
    122    {
    123        ArrayList arraylist = new ArrayList();
    124        ChunkCoordIntPair[] achunkcoordintpair = this.structureCoords;
    125        int i = achunkcoordintpair.length;
    126
    127        for (int j = 0; j < i; ++j)
    128        {
    129            ChunkCoordIntPair chunkcoordintpair = achunkcoordintpair[j];
    130
    131            if (chunkcoordintpair != null)
    132            {
    133                arraylist.add(chunkcoordintpair.getChunkPosition(64));
    134            }
    135        }
    136
    137        return arraylist;
    138    }
    139
    140    protected StructureStart getStructureStart(int par1, int par2)
    141    {
    142        StructureStrongholdStart structurestrongholdstart;
    143
    144        for (structurestrongholdstart = new StructureStrongholdStart(this.worldObj, this.rand, par1, par2); structurestrongholdstart.getComponents().isEmpty() || ((ComponentStrongholdStairs2)structurestrongholdstart.getComponents().get(0)).strongholdPortalRoom == null; structurestrongholdstart = new StructureStrongholdStart(this.worldObj, this.rand, par1, par2))
    145        {
    146            ;
    147        }
    148
    149        return structurestrongholdstart;
    150    }
    151}