RandomSequence .java

net.minecraft.world.RandomSequence (class): members: seedForKey, source, random, CODEC. strings: "source". imports: XoroshiroRandomSource, RandomSupport.

net.minecraft.worldclass46 linescommon1.4 KB

API Surface (2)

RandomSupport.Seed128bit seedForKey(final Identifier key)
RandomSource random()

Fields & Constants (2)

CODEC
source

String literals (1)

"source"

Code Graph: Dependencies (4)

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

Full Source

RandomSequence.java46 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.codecs.RecordCodecBuilder;
5
import java.util.Optional;
6
import net.minecraft.resources.Identifier;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.level.levelgen.RandomSupport;
9
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;
10
11
public class RandomSequence {
12
	public static final Codec<RandomSequence> CODEC = RecordCodecBuilder.create(
13
		i -> i.group(XoroshiroRandomSource.CODEC.fieldOf("source").forGetter(r -> r.source)).apply(i, RandomSequence::new)
14
	);
15
	private final XoroshiroRandomSource source;
16
17
	public RandomSequence(final XoroshiroRandomSource source) {
18
		this.source = source;
19
	}
20
21
	public RandomSequence(final long seed, final Identifier key) {
22
		this(createSequence(seed, Optional.of(key)));
23
	}
24
25
	public RandomSequence(final long seed, final Optional<Identifier> key) {
26
		this(createSequence(seed, key));
27
	}
28
29
	private static XoroshiroRandomSource createSequence(final long seed, final Optional<Identifier> key) {
30
		RandomSupport.Seed128bit seed128bit = RandomSupport.upgradeSeedTo128bitUnmixed(seed);
31
		if (key.isPresent()) {
32
			seed128bit = seed128bit.xor(seedForKey(key.get()));
33
		}
34
35
		return new XoroshiroRandomSource(seed128bit.mixed());
36
	}
37
38
	public static RandomSupport.Seed128bit seedForKey(final Identifier key) {
39
		return RandomSupport.seedFromHashOf(key.toString());
40
	}
41
42
	public RandomSource random() {
43
		return this.source;
44
	}
45
}
46

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