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