File size: 1,850 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package net.minecraft.world;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.mojang.serialization.codecs.RecordCodecBuilder.Instance;
import java.util.Optional;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.RandomSupport;
import net.minecraft.world.level.levelgen.XoroshiroRandomSource;

public class RandomSequence {
    public static final Codec<RandomSequence> CODEC = RecordCodecBuilder.create(
        p_287586_ -> p_287586_.group(XoroshiroRandomSource.CODEC.fieldOf("source").forGetter(p_287757_ -> p_287757_.source))
                .apply(p_287586_, RandomSequence::new)
    );
    private final XoroshiroRandomSource source;

    public RandomSequence(XoroshiroRandomSource p_287597_) {
        this.source = p_287597_;
    }

    public RandomSequence(long p_287592_, ResourceLocation p_287762_) {
        this(createSequence(p_287592_, Optional.of(p_287762_)));
    }

    public RandomSequence(long p_298200_, Optional<ResourceLocation> p_297536_) {
        this(createSequence(p_298200_, p_297536_));
    }

    private static XoroshiroRandomSource createSequence(long p_289567_, Optional<ResourceLocation> p_300474_) {
        RandomSupport.Seed128bit randomsupport$seed128bit = RandomSupport.upgradeSeedTo128bitUnmixed(p_289567_);
        if (p_300474_.isPresent()) {
            randomsupport$seed128bit = randomsupport$seed128bit.xor(seedForKey(p_300474_.get()));
        }

        return new XoroshiroRandomSource(randomsupport$seed128bit.mixed());
    }

    public static RandomSupport.Seed128bit seedForKey(ResourceLocation p_288989_) {
        return RandomSupport.seedFromHashOf(p_288989_.toString());
    }

    public RandomSource random() {
        return this.source;
    }
}