minecraft_25w45a_unobfuscated/net/minecraft/world/level/levelgen/ThreadSafeLegacyRandomSource.java
2025-11-24 22:52:51 +03:00

57 lines
1.7 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world.level.levelgen;
import java.util.concurrent.atomic.AtomicLong;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.BitRandomSource;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian;
import net.minecraft.world.level.levelgen.PositionalRandomFactory;
@Deprecated
public class ThreadSafeLegacyRandomSource
implements BitRandomSource {
private static final int MODULUS_BITS = 48;
private static final long MODULUS_MASK = 0xFFFFFFFFFFFFL;
private static final long MULTIPLIER = 25214903917L;
private static final long INCREMENT = 11L;
private final AtomicLong seed = new AtomicLong();
private final MarsagliaPolarGaussian gaussianSource = new MarsagliaPolarGaussian(this);
public ThreadSafeLegacyRandomSource(long seed) {
this.setSeed(seed);
}
@Override
public RandomSource fork() {
return new ThreadSafeLegacyRandomSource(this.nextLong());
}
@Override
public PositionalRandomFactory forkPositional() {
return new LegacyRandomSource.LegacyPositionalRandomFactory(this.nextLong());
}
@Override
public void setSeed(long seed) {
this.seed.set((seed ^ 0x5DEECE66DL) & 0xFFFFFFFFFFFFL);
}
@Override
public int next(int bits) {
long nextSeed;
long oldSeed;
while (!this.seed.compareAndSet(oldSeed = this.seed.get(), nextSeed = oldSeed * 25214903917L + 11L & 0xFFFFFFFFFFFFL)) {
}
return (int)(nextSeed >>> 48 - bits);
}
@Override
public double nextGaussian() {
return this.gaussianSource.nextGaussian();
}
}