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