    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class NoiseGeneratorPerlin extends NoiseGenerator
    006    {
    007        private int[] permutations;
    008        public double xCoord;
    009        public double yCoord;
    010        public double zCoord;
    011
    012        public NoiseGeneratorPerlin()
    013        {
    014            this(new Random());
    015        }
    016
    017        public NoiseGeneratorPerlin(Random par1Random)
    018        {
    019            this.permutations = new int[512];
    020            this.xCoord = par1Random.nextDouble() * 256.0D;
    021            this.yCoord = par1Random.nextDouble() * 256.0D;
    022            this.zCoord = par1Random.nextDouble() * 256.0D;
    023            int var2;
    024
    025            for (var2 = 0; var2 < 256; this.permutations[var2] = var2++)
    026            {
    027                ;
    028            }
    029
    030            for (var2 = 0; var2 < 256; ++var2)
    031            {
    032                int var3 = par1Random.nextInt(256 - var2) + var2;
    033                int var4 = this.permutations[var2];
    034                this.permutations[var2] = this.permutations[var3];
    035                this.permutations[var3] = var4;
    036                this.permutations[var2 + 256] = this.permutations[var2];
    037            }
    038        }
    039
    040        public final double lerp(double par1, double par3, double par5)
    041        {
    042            return par3 + par1 * (par5 - par3);
    043        }
    044
    045        public final double func_76309_a(int par1, double par2, double par4)
    046        {
    047            int var6 = par1 & 15;
    048            double var7 = (double)(1 - ((var6 & 8) >> 3)) * par2;
    049            double var9 = var6 < 4 ? 0.0D : (var6 != 12 && var6 != 14 ? par4 : par2);
    050            return ((var6 & 1) == 0 ? var7 : -var7) + ((var6 & 2) == 0 ? var9 : -var9);
    051        }
    052
    053        public final double grad(int par1, double par2, double par4, double par6)
    054        {
    055            int var8 = par1 & 15;
    056            double var9 = var8 < 8 ? par2 : par4;
    057            double var11 = var8 < 4 ? par4 : (var8 != 12 && var8 != 14 ? par6 : par2);
    058            return ((var8 & 1) == 0 ? var9 : -var9) + ((var8 & 2) == 0 ? var11 : -var11);
    059        }
    060
    061        /**
    062         * pars: noiseArray , xOffset , yOffset , zOffset , xSize , ySize , zSize , xScale, yScale , zScale , noiseScale.
    063         * noiseArray should be xSize*ySize*zSize in size
    064         */
    065        public void populateNoiseArray(double[] par1ArrayOfDouble, double par2, double par4, double par6, int par8, int par9, int par10, double par11, double par13, double par15, double par17)
    066        {
    067            int var19;
    068            int var22;
    069            double var31;
    070            double var35;
    071            double var38;
    072            int var37;
    073            double var42;
    074            int var40;
    075            int var41;
    076            int var10001;
    077            int var77;
    078
    079            if (par9 == 1)
    080            {
    081                boolean var66 = false;
    082                boolean var65 = false;
    083                boolean var21 = false;
    084                boolean var67 = false;
    085                double var72 = 0.0D;
    086                double var71 = 0.0D;
    087                var77 = 0;
    088                double var74 = 1.0D / par17;
    089
    090                for (int var30 = 0; var30 < par8; ++var30)
    091                {
    092                    var31 = par2 + (double)var30 * par11 + this.xCoord;
    093                    int var78 = (int)var31;
    094
    095                    if (var31 < (double)var78)
    096                    {
    097                        --var78;
    098                    }
    099
    100                    int var34 = var78 & 255;
    101                    var31 -= (double)var78;
    102                    var35 = var31 * var31 * var31 * (var31 * (var31 * 6.0D - 15.0D) + 10.0D);
    103
    104                    for (var37 = 0; var37 < par10; ++var37)
    105                    {
    106                        var38 = par6 + (double)var37 * par15 + this.zCoord;
    107                        var40 = (int)var38;
    108
    109                        if (var38 < (double)var40)
    110                        {
    111                            --var40;
    112                        }
    113
    114                        var41 = var40 & 255;
    115                        var38 -= (double)var40;
    116                        var42 = var38 * var38 * var38 * (var38 * (var38 * 6.0D - 15.0D) + 10.0D);
    117                        var19 = this.permutations[var34] + 0;
    118                        int var64 = this.permutations[var19] + var41;
    119                        int var69 = this.permutations[var34 + 1] + 0;
    120                        var22 = this.permutations[var69] + var41;
    121                        var72 = this.lerp(var35, this.func_76309_a(this.permutations[var64], var31, var38), this.grad(this.permutations[var22], var31 - 1.0D, 0.0D, var38));
    122                        var71 = this.lerp(var35, this.grad(this.permutations[var64 + 1], var31, 0.0D, var38 - 1.0D), this.grad(this.permutations[var22 + 1], var31 - 1.0D, 0.0D, var38 - 1.0D));
    123                        double var79 = this.lerp(var42, var72, var71);
    124                        var10001 = var77++;
    125                        par1ArrayOfDouble[var10001] += var79 * var74;
    126                    }
    127                }
    128            }
    129            else
    130            {
    131                var19 = 0;
    132                double var20 = 1.0D / par17;
    133                var22 = -1;
    134                boolean var23 = false;
    135                boolean var24 = false;
    136                boolean var25 = false;
    137                boolean var26 = false;
    138                boolean var27 = false;
    139                boolean var28 = false;
    140                double var29 = 0.0D;
    141                var31 = 0.0D;
    142                double var33 = 0.0D;
    143                var35 = 0.0D;
    144
    145                for (var37 = 0; var37 < par8; ++var37)
    146                {
    147                    var38 = par2 + (double)var37 * par11 + this.xCoord;
    148                    var40 = (int)var38;
    149
    150                    if (var38 < (double)var40)
    151                    {
    152                        --var40;
    153                    }
    154
    155                    var41 = var40 & 255;
    156                    var38 -= (double)var40;
    157                    var42 = var38 * var38 * var38 * (var38 * (var38 * 6.0D - 15.0D) + 10.0D);
    158
    159                    for (int var44 = 0; var44 < par10; ++var44)
    160                    {
    161                        double var45 = par6 + (double)var44 * par15 + this.zCoord;
    162                        int var47 = (int)var45;
    163
    164                        if (var45 < (double)var47)
    165                        {
    166                            --var47;
    167                        }
    168
    169                        int var48 = var47 & 255;
    170                        var45 -= (double)var47;
    171                        double var49 = var45 * var45 * var45 * (var45 * (var45 * 6.0D - 15.0D) + 10.0D);
    172
    173                        for (int var51 = 0; var51 < par9; ++var51)
    174                        {
    175                            double var52 = par4 + (double)var51 * par13 + this.yCoord;
    176                            int var54 = (int)var52;
    177
    178                            if (var52 < (double)var54)
    179                            {
    180                                --var54;
    181                            }
    182
    183                            int var55 = var54 & 255;
    184                            var52 -= (double)var54;
    185                            double var56 = var52 * var52 * var52 * (var52 * (var52 * 6.0D - 15.0D) + 10.0D);
    186
    187                            if (var51 == 0 || var55 != var22)
    188                            {
    189                                var22 = var55;
    190                                int var68 = this.permutations[var41] + var55;
    191                                int var73 = this.permutations[var68] + var48;
    192                                int var70 = this.permutations[var68 + 1] + var48;
    193                                int var76 = this.permutations[var41 + 1] + var55;
    194                                var77 = this.permutations[var76] + var48;
    195                                int var75 = this.permutations[var76 + 1] + var48;
    196                                var29 = this.lerp(var42, this.grad(this.permutations[var73], var38, var52, var45), this.grad(this.permutations[var77], var38 - 1.0D, var52, var45));
    197                                var31 = this.lerp(var42, this.grad(this.permutations[var70], var38, var52 - 1.0D, var45), this.grad(this.permutations[var75], var38 - 1.0D, var52 - 1.0D, var45));
    198                                var33 = this.lerp(var42, this.grad(this.permutations[var73 + 1], var38, var52, var45 - 1.0D), this.grad(this.permutations[var77 + 1], var38 - 1.0D, var52, var45 - 1.0D));
    199                                var35 = this.lerp(var42, this.grad(this.permutations[var70 + 1], var38, var52 - 1.0D, var45 - 1.0D), this.grad(this.permutations[var75 + 1], var38 - 1.0D, var52 - 1.0D, var45 - 1.0D));
    200                            }
    201
    202                            double var58 = this.lerp(var56, var29, var31);
    203                            double var60 = this.lerp(var56, var33, var35);
    204                            double var62 = this.lerp(var49, var58, var60);
    205                            var10001 = var19++;
    206                            par1ArrayOfDouble[var10001] += var62 * var20;
    207                        }
    208                    }
    209                }
    210            }
    211        }
    212    }