SmearedPerlinNoise .java

net.minecraft.world.level.levelgen.synth.SmearedPerlinNoise (class): members: SHIFT_UP_EPSILON, fudgeYScale, addToVolume, range, get. ann: @Deprecated.

net.minecraft.world.level.levelgen.synthclass151 linescommonextends PerlinNoise5.1 KB

API Surface (4)

Interval range(final double fudgeYScale)
Interval range()
float get(final double _x, final double _y, final double _z)
void addToVolume(final DensityBuffer buffer, final DensityVolume volume, final double xzScale, final double yScale, final float amplitude)

Fields & Constants (2)

SHIFT_UP_EPSILON
fudgeYScale

Code Graph: Dependencies (7)

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

Full Source

SmearedPerlinNoise.java151 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.synth;
2
3
import net.minecraft.util.Interval;
4
import net.minecraft.util.Mth;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.world.level.levelgen.densityfunction.DensityBuffer;
7
import net.minecraft.world.level.levelgen.densityfunction.DensityVolume;
8
9
@Deprecated
10
public class SmearedPerlinNoise extends PerlinNoise {
11
	private static final float SHIFT_UP_EPSILON = 1.0E-7F;
12
	private final double fudgeYScale;
13
14
	public SmearedPerlinNoise(final RandomSource random, final double fudgeYScale) {
15
		super(random);
16
		this.fudgeYScale = fudgeYScale;
17
	}
18
19
	public static Interval range(final double fudgeYScale) {
20
		return Interval.ofSymmetric((float)(Math.abs(fudgeYScale) + 2.0));
21
	}
22
23
	@Override
24
	public Interval range() {
25
		return range(this.fudgeYScale);
26
	}
27
28
	@Override
29
	public float get(final double _x, final double _y, final double _z) {
30
		double x = wrap(_x) + this.offsetX;
31
		double y = wrap(_y) + this.offsetY;
32
		double z = wrap(_z) + this.offsetZ;
33
		int floorX = Mth.floor(x);
34
		int floorY = Mth.floor(y);
35
		int floorZ = Mth.floor(z);
36
		float relativeX = (float)(x - floorX);
37
		double relativeY = y - floorY;
38
		float relativeZ = (float)(z - floorZ);
39
		float fudgedRelativeY = (float)(relativeY - this.computeFudgeY(_y, relativeY));
40
		return this.sampleAndLerp(floorX, floorY, floorZ, relativeX, fudgedRelativeY, relativeZ, (float)relativeY);
41
	}
42
43
	private double computeFudgeY(final double originalY, final double relativeY) {
44
		double fudgeLimit;
45
		if (originalY >= 0.0 && originalY < relativeY) {
46
			fudgeLimit = originalY;
47
		} else {
48
			fudgeLimit = relativeY;
49
		}
50
51
		return Mth.floor(fudgeLimit / this.fudgeYScale + 1.0E-7F) * this.fudgeYScale;
52
	}
53
54
	@Override
55
	public void addToVolume(final DensityBuffer buffer, final DensityVolume volume, final double xzScale, final double yScale, final float amplitude) {
56
		float d000xz = 0.0F;
57
		float d100xz = 0.0F;
58
		float d010xz = 0.0F;
59
		float d110xz = 0.0F;
60
		float d001xz = 0.0F;
61
		float d101xz = 0.0F;
62
		float d011xz = 0.0F;
63
		float d111xz = 0.0F;
64
		float g000y = 0.0F;
65
		float g100y = 0.0F;
66
		float g010y = 0.0F;
67
		float g110y = 0.0F;
68
		float g001y = 0.0F;
69
		float g101y = 0.0F;
70
		float g011y = 0.0F;
71
		float g111y = 0.0F;
72
		int index = 0;
73
74
		for (int indexZ = 0; indexZ < volume.sizeZ(); indexZ++) {
75
			double z = wrap(volume.blockZ(indexZ) * xzScale) + this.offsetZ;
76
			int floorZ = Mth.floor(z);
77
			float relativeZ = (float)(z - floorZ);
78
			float alphaZ = Mth.smoothstep(relativeZ);
79
80
			for (int indexX = 0; indexX < volume.sizeX(); indexX++) {
81
				double x = wrap(volume.blockX(indexX) * xzScale) + this.offsetX;
82
				int floorX = Mth.floor(x);
83
				float relativeX = (float)(x - floorX);
84
				int x0 = this.permute(floorX);
85
				int x1 = this.permute(floorX + 1);
86
				float alphaX = Mth.smoothstep(relativeX);
87
				int lastFloorY = Integer.MIN_VALUE;
88
89
				for (int indexY = 0; indexY < volume.sizeY(); indexY++) {
90
					double originalY = volume.blockY(indexY) * yScale;
91
					double y = wrap(originalY) + this.offsetY;
92
					int floorY = Mth.floor(y);
93
					double relativeY = y - floorY;
94
					float alphaY = Mth.smoothstep((float)relativeY);
95
					if (lastFloorY != floorY) {
96
						int xy00 = this.permute(x0 + floorY);
97
						int xy01 = this.permute(x0 + floorY + 1);
98
						int xy10 = this.permute(x1 + floorY);
99
						int xy11 = this.permute(x1 + floorY + 1);
100
						GradientNoise.Gradient g000 = this.permuteToGrad(xy00 + floorZ);
101
						d000xz = g000.dotXz(relativeX, relativeZ);
102
						g000y = g000.y();
103
						GradientNoise.Gradient g100 = this.permuteToGrad(xy10 + floorZ);
104
						d100xz = g100.dotXz(relativeX - 1.0F, relativeZ);
105
						g100y = g100.y();
106
						GradientNoise.Gradient g010 = this.permuteToGrad(xy01 + floorZ);
107
						d010xz = g010.dotXz(relativeX, relativeZ);
108
						g010y = g010.y();
109
						GradientNoise.Gradient g110 = this.permuteToGrad(xy11 + floorZ);
110
						d110xz = g110.dotXz(relativeX - 1.0F, relativeZ);
111
						g110y = g110.y();
112
						GradientNoise.Gradient g001 = this.permuteToGrad(xy00 + floorZ + 1);
113
						d001xz = g001.dotXz(relativeX, relativeZ - 1.0F);
114
						g001y = g001.y();
115
						GradientNoise.Gradient g101 = this.permuteToGrad(xy10 + floorZ + 1);
116
						d101xz = g101.dotXz(relativeX - 1.0F, relativeZ - 1.0F);
117
						g101y = g101.y();
118
						GradientNoise.Gradient g011 = this.permuteToGrad(xy01 + floorZ + 1);
119
						d011xz = g011.dotXz(relativeX, relativeZ - 1.0F);
120
						g011y = g011.y();
121
						GradientNoise.Gradient g111 = this.permuteToGrad(xy11 + floorZ + 1);
122
						d111xz = g111.dotXz(relativeX - 1.0F, relativeZ - 1.0F);
123
						g111y = g111.y();
124
						lastFloorY = floorY;
125
					}
126
127
					float fudgedRelativeY = (float)(relativeY - this.computeFudgeY(originalY, relativeY));
128
					buffer.addTo(
129
						index,
130
						amplitude
131
							* Mth.lerp3(
132
								alphaX,
133
								alphaY,
134
								alphaZ,
135
								d000xz + g000y * fudgedRelativeY,
136
								d100xz + g100y * fudgedRelativeY,
137
								d010xz + g010y * (fudgedRelativeY - 1.0F),
138
								d110xz + g110y * (fudgedRelativeY - 1.0F),
139
								d001xz + g001y * fudgedRelativeY,
140
								d101xz + g101y * fudgedRelativeY,
141
								d011xz + g011y * (fudgedRelativeY - 1.0F),
142
								d111xz + g111y * (fudgedRelativeY - 1.0F)
143
							)
144
					);
145
					index++;
146
				}
147
			}
148
		}
149
	}
150
}
151

Decompiled Minecraft 26.3 source of SmearedPerlinNoise (net/minecraft/world/level/levelgen/synth/SmearedPerlinNoise.java) with Mojang official mappings, stored verbatim on the site.