WorldgenRandom .java

net.minecraft.world.level.levelgen.WorldgenRandom (class): members: setLargeFeatureWithSalt, setLargeFeatureSeed, setDecorationSeed, seedSlimeChunk, fork.

net.minecraft.world.level.levelgenclass88 linescommonextends LegacyRandomSource2.4 KB

API Surface (11)

int getCount()
RandomSource fork()
PositionalRandomFactory forkPositional()
int next(final int bits)
void setSeed(final long seed)
long setDecorationSeed(final long seed, final int chunkX, final int chunkZ)
void setFeatureSeed(final long seed, final int index, final int step)
void setLargeFeatureSeed(final long seed, final int chunkX, final int chunkZ)
void setLargeFeatureWithSalt(final long seed, final int x, final int z, final int blend)
RandomSource seedSlimeChunk(final int x, final int z, final long seed, final long salt)
RandomSource newInstance(final long seed)

Fields & Constants (2)

randomSource
count

Code Graph: Dependencies (3)

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

Full Source

WorldgenRandom.java88 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen;
2
3
import java.util.function.LongFunction;
4
import net.minecraft.util.RandomSource;
5
6
public class WorldgenRandom extends LegacyRandomSource {
7
	private final RandomSource randomSource;
8
	private int count;
9
10
	public WorldgenRandom(final RandomSource randomSource) {
11
		super(0L);
12
		this.randomSource = randomSource;
13
	}
14
15
	public int getCount() {
16
		return this.count;
17
	}
18
19
	@Override
20
	public RandomSource fork() {
21
		return this.randomSource.fork();
22
	}
23
24
	@Override
25
	public PositionalRandomFactory forkPositional() {
26
		return this.randomSource.forkPositional();
27
	}
28
29
	@Override
30
	public int next(final int bits) {
31
		this.count++;
32
		return this.randomSource instanceof LegacyRandomSource legacyRandomSource ? legacyRandomSource.next(bits) : (int)(this.randomSource.nextLong() >>> 64 - bits);
33
	}
34
35
	@Override
36
	public synchronized void setSeed(final long seed) {
37
		if (this.randomSource != null) {
38
			this.randomSource.setSeed(seed);
39
		}
40
	}
41
42
	public long setDecorationSeed(final long seed, final int chunkX, final int chunkZ) {
43
		this.setSeed(seed);
44
		long xScale = this.nextLong() | 1L;
45
		long zScale = this.nextLong() | 1L;
46
		long result = chunkX * xScale + chunkZ * zScale ^ seed;
47
		this.setSeed(result);
48
		return result;
49
	}
50
51
	public void setFeatureSeed(final long seed, final int index, final int step) {
52
		long result = seed + index + 10000 * step;
53
		this.setSeed(result);
54
	}
55
56
	public void setLargeFeatureSeed(final long seed, final int chunkX, final int chunkZ) {
57
		this.setSeed(seed);
58
		long xScale = this.nextLong();
59
		long zScale = this.nextLong();
60
		long result = chunkX * xScale ^ chunkZ * zScale ^ seed;
61
		this.setSeed(result);
62
	}
63
64
	public void setLargeFeatureWithSalt(final long seed, final int x, final int z, final int blend) {
65
		long result = x * 341873128712L + z * 132897987541L + seed + blend;
66
		this.setSeed(result);
67
	}
68
69
	public static RandomSource seedSlimeChunk(final int x, final int z, final long seed, final long salt) {
70
		return RandomSource.createThreadLocalInstance(seed + x * x * 4987142 + x * 5947611 + z * z * 4392871L + z * 389711 ^ salt);
71
	}
72
73
	public enum Algorithm {
74
		LEGACY(LegacyRandomSource::new),
75
		XOROSHIRO(XoroshiroRandomSource::new);
76
77
		private final LongFunction<RandomSource> constructor;
78
79
		Algorithm(final LongFunction<RandomSource> constructor) {
80
			this.constructor = constructor;
81
		}
82
83
		public RandomSource newInstance(final long seed) {
84
			return this.constructor.apply(seed);
85
		}
86
	}
87
}
88

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