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