NoiseGeneratorImproved .java

net.minecraft.world.gen.NoiseGeneratorImproved (class, 206 lines): members: populateNoiseArray, field_152381_e, field_152382_f, field_152383_g, grad, lerp.

net.minecraft.world.genclass206 linescommonextends NoiseGenerator8.0 KB

API Surface (4)

double lerp(double p_76311_1_, double p_76311_3_, double p_76311_5_)
double func_76309_a(int p_76309_1_, double p_76309_2_, double p_76309_4_)
double grad(int p_76310_1_, double p_76310_2_, double p_76310_4_, double p_76310_6_)
void populateNoiseArray(double[] noiseArray, double xOffset, double yOffset, double zOffset, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale, double noiseScale)

Fields & Constants (9)

field_152381_e
field_152382_f
field_152383_g
field_152384_h
field_152385_i
permutations
xCoord
yCoord
zCoord

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

NoiseGeneratorImproved.java206 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen;
2
3
import java.util.Random;
4
5
public class NoiseGeneratorImproved extends NoiseGenerator
6
{
7
    /**
8
     * An int[512], where the first 256 elements are the numbers 0..255, in random shuffled order,
9
     * and the second half of the array is identical to the first half, apparently for convenience in wrapping lookups.
10
     *  
11
     * Effectively a shuffled 0..255 that wraps once.
12
     */
13
    private int[] permutations;
14
    public double xCoord;
15
    public double yCoord;
16
    public double zCoord;
17
    private static final double[] field_152381_e = new double[] {1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, -1.0D, 0.0D};
18
    private static final double[] field_152382_f = new double[] {1.0D, 1.0D, -1.0D, -1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D};
19
    private static final double[] field_152383_g = new double[] {0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, -1.0D, -1.0D, 1.0D, 1.0D, -1.0D, -1.0D, 0.0D, 1.0D, 0.0D, -1.0D};
20
    private static final double[] field_152384_h = new double[] {1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D, 1.0D, -1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, -1.0D, 0.0D};
21
    private static final double[] field_152385_i = new double[] {0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, -1.0D, -1.0D, 1.0D, 1.0D, -1.0D, -1.0D, 0.0D, 1.0D, 0.0D, -1.0D};
22
23
    public NoiseGeneratorImproved()
24
    {
25
        this(new Random());
26
    }
27
28
    public NoiseGeneratorImproved(Random p_i45469_1_)
29
    {
30
        this.permutations = new int[512];
31
        this.xCoord = p_i45469_1_.nextDouble() * 256.0D;
32
        this.yCoord = p_i45469_1_.nextDouble() * 256.0D;
33
        this.zCoord = p_i45469_1_.nextDouble() * 256.0D;
34
35
        for (int i = 0; i < 256; this.permutations[i] = i++)
36
        {
37
            ;
38
        }
39
40
        for (int l = 0; l < 256; ++l)
41
        {
42
            int j = p_i45469_1_.nextInt(256 - l) + l;
43
            int k = this.permutations[l];
44
            this.permutations[l] = this.permutations[j];
45
            this.permutations[j] = k;
46
            this.permutations[l + 256] = this.permutations[l];
47
        }
48
    }
49
50
    public final double lerp(double p_76311_1_, double p_76311_3_, double p_76311_5_)
51
    {
52
        return p_76311_3_ + p_76311_1_ * (p_76311_5_ - p_76311_3_);
53
    }
54
55
    public final double func_76309_a(int p_76309_1_, double p_76309_2_, double p_76309_4_)
56
    {
57
        int i = p_76309_1_ & 15;
58
        return field_152384_h[i] * p_76309_2_ + field_152385_i[i] * p_76309_4_;
59
    }
60
61
    public final double grad(int p_76310_1_, double p_76310_2_, double p_76310_4_, double p_76310_6_)
62
    {
63
        int i = p_76310_1_ & 15;
64
        return field_152381_e[i] * p_76310_2_ + field_152382_f[i] * p_76310_4_ + field_152383_g[i] * p_76310_6_;
65
    }
66
67
    /**
68
     * noiseArray should be xSize*ySize*zSize in size
69
     */
70
    public void populateNoiseArray(double[] noiseArray, double xOffset, double yOffset, double zOffset, int xSize, int ySize, int zSize, double xScale, double yScale, double zScale, double noiseScale)
71
    {
72
        if (ySize == 1)
73
        {
74
            int i5 = 0;
75
            int j5 = 0;
76
            int j = 0;
77
            int k5 = 0;
78
            double d14 = 0.0D;
79
            double d15 = 0.0D;
80
            int l5 = 0;
81
            double d16 = 1.0D / noiseScale;
82
83
            for (int j2 = 0; j2 < xSize; ++j2)
84
            {
85
                double d17 = xOffset + (double)j2 * xScale + this.xCoord;
86
                int i6 = (int)d17;
87
88
                if (d17 < (double)i6)
89
                {
90
                    --i6;
91
                }
92
93
                int k2 = i6 & 255;
94
                d17 = d17 - (double)i6;
95
                double d18 = d17 * d17 * d17 * (d17 * (d17 * 6.0D - 15.0D) + 10.0D);
96
97
                for (int j6 = 0; j6 < zSize; ++j6)
98
                {
99
                    double d19 = zOffset + (double)j6 * zScale + this.zCoord;
100
                    int k6 = (int)d19;
101
102
                    if (d19 < (double)k6)
103
                    {
104
                        --k6;
105
                    }
106
107
                    int l6 = k6 & 255;
108
                    d19 = d19 - (double)k6;
109
                    double d20 = d19 * d19 * d19 * (d19 * (d19 * 6.0D - 15.0D) + 10.0D);
110
                    i5 = this.permutations[k2] + 0;
111
                    j5 = this.permutations[i5] + l6;
112
                    j = this.permutations[k2 + 1] + 0;
113
                    k5 = this.permutations[j] + l6;
114
                    d14 = this.lerp(d18, this.func_76309_a(this.permutations[j5], d17, d19), this.grad(this.permutations[k5], d17 - 1.0D, 0.0D, d19));
115
                    d15 = this.lerp(d18, this.grad(this.permutations[j5 + 1], d17, 0.0D, d19 - 1.0D), this.grad(this.permutations[k5 + 1], d17 - 1.0D, 0.0D, d19 - 1.0D));
116
                    double d21 = this.lerp(d20, d14, d15);
117
                    int i7 = l5++;
118
                    noiseArray[i7] += d21 * d16;
119
                }
120
            }
121
        }
122
        else
123
        {
124
            int i = 0;
125
            double d0 = 1.0D / noiseScale;
126
            int k = -1;
127
            int l = 0;
128
            int i1 = 0;
129
            int j1 = 0;
130
            int k1 = 0;
131
            int l1 = 0;
132
            int i2 = 0;
133
            double d1 = 0.0D;
134
            double d2 = 0.0D;
135
            double d3 = 0.0D;
136
            double d4 = 0.0D;
137
138
            for (int l2 = 0; l2 < xSize; ++l2)
139
            {
140
                double d5 = xOffset + (double)l2 * xScale + this.xCoord;
141
                int i3 = (int)d5;
142
143
                if (d5 < (double)i3)
144
                {
145
                    --i3;
146
                }
147
148
                int j3 = i3 & 255;
149
                d5 = d5 - (double)i3;
150
                double d6 = d5 * d5 * d5 * (d5 * (d5 * 6.0D - 15.0D) + 10.0D);
151
152
                for (int k3 = 0; k3 < zSize; ++k3)
153
                {
154
                    double d7 = zOffset + (double)k3 * zScale + this.zCoord;
155
                    int l3 = (int)d7;
156
157
                    if (d7 < (double)l3)
158
                    {
159
                        --l3;
160
                    }
161
162
                    int i4 = l3 & 255;
163
                    d7 = d7 - (double)l3;
164
                    double d8 = d7 * d7 * d7 * (d7 * (d7 * 6.0D - 15.0D) + 10.0D);
165
166
                    for (int j4 = 0; j4 < ySize; ++j4)
167
                    {
168
                        double d9 = yOffset + (double)j4 * yScale + this.yCoord;
169
                        int k4 = (int)d9;
170
171
                        if (d9 < (double)k4)
172
                        {
173
                            --k4;
174
                        }
175
176
                        int l4 = k4 & 255;
177
                        d9 = d9 - (double)k4;
178
                        double d10 = d9 * d9 * d9 * (d9 * (d9 * 6.0D - 15.0D) + 10.0D);
179
180
                        if (j4 == 0 || l4 != k)
181
                        {
182
                            k = l4;
183
                            l = this.permutations[j3] + l4;
184
                            i1 = this.permutations[l] + i4;
185
                            j1 = this.permutations[l + 1] + i4;
186
                            k1 = this.permutations[j3 + 1] + l4;
187
                            l1 = this.permutations[k1] + i4;
188
                            i2 = this.permutations[k1 + 1] + i4;
189
                            d1 = this.lerp(d6, this.grad(this.permutations[i1], d5, d9, d7), this.grad(this.permutations[l1], d5 - 1.0D, d9, d7));
190
                            d2 = this.lerp(d6, this.grad(this.permutations[j1], d5, d9 - 1.0D, d7), this.grad(this.permutations[i2], d5 - 1.0D, d9 - 1.0D, d7));
191
                            d3 = this.lerp(d6, this.grad(this.permutations[i1 + 1], d5, d9, d7 - 1.0D), this.grad(this.permutations[l1 + 1], d5 - 1.0D, d9, d7 - 1.0D));
192
                            d4 = this.lerp(d6, this.grad(this.permutations[j1 + 1], d5, d9 - 1.0D, d7 - 1.0D), this.grad(this.permutations[i2 + 1], d5 - 1.0D, d9 - 1.0D, d7 - 1.0D));
193
                        }
194
195
                        double d11 = this.lerp(d10, d1, d2);
196
                        double d12 = this.lerp(d10, d3, d4);
197
                        double d13 = this.lerp(d8, d11, d12);
198
                        int j7 = i++;
199
                        noiseArray[j7] += d13 * d0;
200
                    }
201
                }
202
            }
203
        }
204
    }
205
}
206

Deobfuscated MCP 1.8.9 source of NoiseGeneratorImproved from Marcelektro/MavenMCP-1.8.9 (net/minecraft/world/gen/NoiseGeneratorImproved.java), stored verbatim.