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