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