    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class MapGenCaves extends MapGenBase
    006    {
    007        /**
    008         * Generates a larger initial cave node than usual. Called 25% of the time.
    009         */
    010        protected void generateLargeCaveNode(long par1, int par3, int par4, byte[] par5ArrayOfByte, double par6, double par8, double par10)
    011        {
    012            this.generateCaveNode(par1, par3, par4, par5ArrayOfByte, par6, par8, par10, 1.0F + this.rand.nextFloat() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
    013        }
    014
    015        /**
    016         * Generates a node in the current cave system recursion tree.
    017         */
    018        protected void generateCaveNode(long par1, int par3, int par4, byte[] par5ArrayOfByte, double par6, double par8, double par10, float par12, float par13, float par14, int par15, int par16, double par17)
    019        {
    020            double var19 = (double)(par3 * 16 + 8);
    021            double var21 = (double)(par4 * 16 + 8);
    022            float var23 = 0.0F;
    023            float var24 = 0.0F;
    024            Random var25 = new Random(par1);
    025
    026            if (par16 <= 0)
    027            {
    028                int var26 = this.range * 16 - 16;
    029                par16 = var26 - var25.nextInt(var26 / 4);
    030            }
    031
    032            boolean var54 = false;
    033
    034            if (par15 == -1)
    035            {
    036                par15 = par16 / 2;
    037                var54 = true;
    038            }
    039
    040            int var27 = var25.nextInt(par16 / 2) + par16 / 4;
    041
    042            for (boolean var28 = var25.nextInt(6) == 0; par15 < par16; ++par15)
    043            {
    044                double var29 = 1.5D + (double)(MathHelper.sin((float)par15 * (float)Math.PI / (float)par16) * par12 * 1.0F);
    045                double var31 = var29 * par17;
    046                float var33 = MathHelper.cos(par14);
    047                float var34 = MathHelper.sin(par14);
    048                par6 += (double)(MathHelper.cos(par13) * var33);
    049                par8 += (double)var34;
    050                par10 += (double)(MathHelper.sin(par13) * var33);
    051
    052                if (var28)
    053                {
    054                    par14 *= 0.92F;
    055                }
    056                else
    057                {
    058                    par14 *= 0.7F;
    059                }
    060
    061                par14 += var24 * 0.1F;
    062                par13 += var23 * 0.1F;
    063                var24 *= 0.9F;
    064                var23 *= 0.75F;
    065                var24 += (var25.nextFloat() - var25.nextFloat()) * var25.nextFloat() * 2.0F;
    066                var23 += (var25.nextFloat() - var25.nextFloat()) * var25.nextFloat() * 4.0F;
    067
    068                if (!var54 && par15 == var27 && par12 > 1.0F && par16 > 0)
    069                {
    070                    this.generateCaveNode(var25.nextLong(), par3, par4, par5ArrayOfByte, par6, par8, par10, var25.nextFloat() * 0.5F + 0.5F, par13 - ((float)Math.PI / 2F), par14 / 3.0F, par15, par16, 1.0D);
    071                    this.generateCaveNode(var25.nextLong(), par3, par4, par5ArrayOfByte, par6, par8, par10, var25.nextFloat() * 0.5F + 0.5F, par13 + ((float)Math.PI / 2F), par14 / 3.0F, par15, par16, 1.0D);
    072                    return;
    073                }
    074
    075                if (var54 || var25.nextInt(4) != 0)
    076                {
    077                    double var35 = par6 - var19;
    078                    double var37 = par10 - var21;
    079                    double var39 = (double)(par16 - par15);
    080                    double var41 = (double)(par12 + 2.0F + 16.0F);
    081
    082                    if (var35 * var35 + var37 * var37 - var39 * var39 > var41 * var41)
    083                    {
    084                        return;
    085                    }
    086
    087                    if (par6 >= var19 - 16.0D - var29 * 2.0D && par10 >= var21 - 16.0D - var29 * 2.0D && par6 <= var19 + 16.0D + var29 * 2.0D && par10 <= var21 + 16.0D + var29 * 2.0D)
    088                    {
    089                        int var55 = MathHelper.floor_double(par6 - var29) - par3 * 16 - 1;
    090                        int var36 = MathHelper.floor_double(par6 + var29) - par3 * 16 + 1;
    091                        int var57 = MathHelper.floor_double(par8 - var31) - 1;
    092                        int var38 = MathHelper.floor_double(par8 + var31) + 1;
    093                        int var56 = MathHelper.floor_double(par10 - var29) - par4 * 16 - 1;
    094                        int var40 = MathHelper.floor_double(par10 + var29) - par4 * 16 + 1;
    095
    096                        if (var55 < 0)
    097                        {
    098                            var55 = 0;
    099                        }
    100
    101                        if (var36 > 16)
    102                        {
    103                            var36 = 16;
    104                        }
    105
    106                        if (var57 < 1)
    107                        {
    108                            var57 = 1;
    109                        }
    110
    111                        if (var38 > 120)
    112                        {
    113                            var38 = 120;
    114                        }
    115
    116                        if (var56 < 0)
    117                        {
    118                            var56 = 0;
    119                        }
    120
    121                        if (var40 > 16)
    122                        {
    123                            var40 = 16;
    124                        }
    125
    126                        boolean var58 = false;
    127                        int var42;
    128                        int var45;
    129
    130                        for (var42 = var55; !var58 && var42 < var36; ++var42)
    131                        {
    132                            for (int var43 = var56; !var58 && var43 < var40; ++var43)
    133                            {
    134                                for (int var44 = var38 + 1; !var58 && var44 >= var57 - 1; --var44)
    135                                {
    136                                    var45 = (var42 * 16 + var43) * 128 + var44;
    137
    138                                    if (var44 >= 0 && var44 < 128)
    139                                    {
    140                                        if (par5ArrayOfByte[var45] == Block.waterMoving.blockID || par5ArrayOfByte[var45] == Block.waterStill.blockID)
    141                                        {
    142                                            var58 = true;
    143                                        }
    144
    145                                        if (var44 != var57 - 1 && var42 != var55 && var42 != var36 - 1 && var43 != var56 && var43 != var40 - 1)
    146                                        {
    147                                            var44 = var57;
    148                                        }
    149                                    }
    150                                }
    151                            }
    152                        }
    153
    154                        if (!var58)
    155                        {
    156                            for (var42 = var55; var42 < var36; ++var42)
    157                            {
    158                                double var59 = ((double)(var42 + par3 * 16) + 0.5D - par6) / var29;
    159
    160                                for (var45 = var56; var45 < var40; ++var45)
    161                                {
    162                                    double var46 = ((double)(var45 + par4 * 16) + 0.5D - par10) / var29;
    163                                    int var48 = (var42 * 16 + var45) * 128 + var38;
    164                                    boolean var49 = false;
    165
    166                                    if (var59 * var59 + var46 * var46 < 1.0D)
    167                                    {
    168                                        for (int var50 = var38 - 1; var50 >= var57; --var50)
    169                                        {
    170                                            double var51 = ((double)var50 + 0.5D - par8) / var31;
    171
    172                                            if (var51 > -0.7D && var59 * var59 + var51 * var51 + var46 * var46 < 1.0D)
    173                                            {
    174                                                byte var53 = par5ArrayOfByte[var48];
    175
    176                                                if (var53 == Block.grass.blockID)
    177                                                {
    178                                                    var49 = true;
    179                                                }
    180
    181                                                if (var53 == Block.stone.blockID || var53 == Block.dirt.blockID || var53 == Block.grass.blockID)
    182                                                {
    183                                                    if (var50 < 10)
    184                                                    {
    185                                                        par5ArrayOfByte[var48] = (byte)Block.lavaMoving.blockID;
    186                                                    }
    187                                                    else
    188                                                    {
    189                                                        par5ArrayOfByte[var48] = 0;
    190
    191                                                        if (var49 && par5ArrayOfByte[var48 - 1] == Block.dirt.blockID)
    192                                                        {
    193                                                            par5ArrayOfByte[var48 - 1] = this.worldObj.getBiomeGenForCoords(var42 + par3 * 16, var45 + par4 * 16).topBlock;
    194                                                        }
    195                                                    }
    196                                                }
    197                                            }
    198
    199                                            --var48;
    200                                        }
    201                                    }
    202                                }
    203                            }
    204
    205                            if (var54)
    206                            {
    207                                break;
    208                            }
    209                        }
    210                    }
    211                }
    212            }
    213        }
    214
    215        /**
    216         * Recursively called by generate() (generate) and optionally by itself.
    217         */
    218        protected void recursiveGenerate(World par1World, int par2, int par3, int par4, int par5, byte[] par6ArrayOfByte)
    219        {
    220            int var7 = this.rand.nextInt(this.rand.nextInt(this.rand.nextInt(40) + 1) + 1);
    221
    222            if (this.rand.nextInt(15) != 0)
    223            {
    224                var7 = 0;
    225            }
    226
    227            for (int var8 = 0; var8 < var7; ++var8)
    228            {
    229                double var9 = (double)(par2 * 16 + this.rand.nextInt(16));
    230                double var11 = (double)this.rand.nextInt(this.rand.nextInt(120) + 8);
    231                double var13 = (double)(par3 * 16 + this.rand.nextInt(16));
    232                int var15 = 1;
    233
    234                if (this.rand.nextInt(4) == 0)
    235                {
    236                    this.generateLargeCaveNode(this.rand.nextLong(), par4, par5, par6ArrayOfByte, var9, var11, var13);
    237                    var15 += this.rand.nextInt(4);
    238                }
    239
    240                for (int var16 = 0; var16 < var15; ++var16)
    241                {
    242                    float var17 = this.rand.nextFloat() * (float)Math.PI * 2.0F;
    243                    float var18 = (this.rand.nextFloat() - 0.5F) * 2.0F / 8.0F;
    244                    float var19 = this.rand.nextFloat() * 2.0F + this.rand.nextFloat();
    245
    246                    if (this.rand.nextInt(10) == 0)
    247                    {
    248                        var19 *= this.rand.nextFloat() * this.rand.nextFloat() * 3.0F + 1.0F;
    249                    }
    250
    251                    this.generateCaveNode(this.rand.nextLong(), par4, par5, par6ArrayOfByte, var9, var11, var13, var19, var17, var18, 0, 0, 1.0D);
    252                }
    253            }
    254        }
    255    }