    001    package net.minecraft.world.gen.structure;
    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    import net.minecraft.util.MathHelper;
    012    import net.minecraft.world.ChunkCoordIntPair;
    013    import net.minecraft.world.ChunkPosition;
    014    import net.minecraft.world.biome.BiomeGenBase;
    015
    016    public 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 var2 = par1Map.entrySet().iterator();
    044
    045            while (var2.hasNext())
    046            {
    047                Entry var3 = (Entry)var2.next();
    048
    049                if (((String)var3.getKey()).equals("distance"))
    050                {
    051                    this.field_82671_h = MathHelper.func_82713_a((String)var3.getValue(), this.field_82671_h, 1.0D);
    052                }
    053                else if (((String)var3.getKey()).equals("count"))
    054                {
    055                    this.structureCoords = new ChunkCoordIntPair[MathHelper.parseIntWithDefaultAndMax((String)var3.getValue(), this.structureCoords.length, 1)];
    056                }
    057                else if (((String)var3.getKey()).equals("spread"))
    058                {
    059                    this.field_82672_i = MathHelper.parseIntWithDefaultAndMax((String)var3.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 var3 = new Random();
    069                var3.setSeed(this.worldObj.getSeed());
    070                double var4 = var3.nextDouble() * Math.PI * 2.0D;
    071                int var6 = 1;
    072
    073                for (int var7 = 0; var7 < this.structureCoords.length; ++var7)
    074                {
    075                    double var8 = (1.25D * (double)var6 + var3.nextDouble()) * this.field_82671_h * (double)var6;
    076                    int var10 = (int)Math.round(Math.cos(var4) * var8);
    077                    int var11 = (int)Math.round(Math.sin(var4) * var8);
    078                    ArrayList var12 = new ArrayList();
    079                    Collections.addAll(var12, this.allowedBiomeGenBases);
    080                    ChunkPosition var13 = this.worldObj.getWorldChunkManager().findBiomePosition((var10 << 4) + 8, (var11 << 4) + 8, 112, var12, var3);
    081
    082                    if (var13 != null)
    083                    {
    084                        var10 = var13.x >> 4;
    085                        var11 = var13.z >> 4;
    086                    }
    087
    088                    this.structureCoords[var7] = new ChunkCoordIntPair(var10, var11);
    089                    var4 += (Math.PI * 2D) * (double)var6 / (double)this.field_82672_i;
    090
    091                    if (var7 == this.field_82672_i)
    092                    {
    093                        var6 += 2 + var3.nextInt(5);
    094                        this.field_82672_i += 1 + var3.nextInt(2);
    095                    }
    096                }
    097
    098                this.ranBiomeCheck = true;
    099            }
    100
    101            ChunkCoordIntPair[] var14 = this.structureCoords;
    102            int var15 = var14.length;
    103
    104            for (int var5 = 0; var5 < var15; ++var5)
    105            {
    106                ChunkCoordIntPair var16 = var14[var5];
    107
    108                if (par1 == var16.chunkXPos && par2 == var16.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 var1 = new ArrayList();
    124            ChunkCoordIntPair[] var2 = this.structureCoords;
    125            int var3 = var2.length;
    126
    127            for (int var4 = 0; var4 < var3; ++var4)
    128            {
    129                ChunkCoordIntPair var5 = var2[var4];
    130
    131                if (var5 != null)
    132                {
    133                    var1.add(var5.getChunkPosition(64));
    134                }
    135            }
    136
    137            return var1;
    138        }
    139
    140        protected StructureStart getStructureStart(int par1, int par2)
    141        {
    142            StructureStrongholdStart var3;
    143
    144            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))
    145            {
    146                ;
    147            }
    148
    149            return var3;
    150        }
    151    }