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