private the internal state of positional random

This commit is contained in:
DBotThePony 2025-03-09 21:29:43 +07:00
parent 32fe6e754c
commit 3a08552345
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 9 additions and 9 deletions

View File

@ -5,7 +5,7 @@ import net.minecraft.util.RandomSource
import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian import net.minecraft.world.level.levelgen.MarsagliaPolarGaussian
import net.minecraft.world.level.levelgen.PositionalRandomFactory import net.minecraft.world.level.levelgen.PositionalRandomFactory
import net.minecraft.world.level.levelgen.RandomSupport import net.minecraft.world.level.levelgen.RandomSupport
import ru.dbotthepony.kommons.random.LCG64Random import ru.dbotthepony.kommons.random.PCG32Random
import java.lang.StringBuilder import java.lang.StringBuilder
import java.util.random.RandomGenerator import java.util.random.RandomGenerator
@ -23,7 +23,7 @@ class CMWCRandom(seed: Long = RandomSupport.generateUniqueSeed()) : RandomGenera
} }
override fun setSeed(seed: Long) { override fun setSeed(seed: Long) {
val rng = LCG64Random(seed) val rng = PCG32Random(seed)
// init state with regular LCG produced values // init state with regular LCG produced values
for (i in 1 until state.size) { for (i in 1 until state.size) {
@ -92,7 +92,7 @@ class CMWCRandom(seed: Long = RandomSupport.generateUniqueSeed()) : RandomGenera
return Positional(nextLong()) return Positional(nextLong())
} }
class Positional(val seed: Long) : PositionalRandomFactory { class Positional(private val seed: Long) : PositionalRandomFactory {
override fun at(x: Int, y: Int, z: Int): RandomSource { override fun at(x: Int, y: Int, z: Int): RandomSource {
return CMWCRandom(Mth.getSeed(x, y, z).xor(seed)) return CMWCRandom(Mth.getSeed(x, y, z).xor(seed))
} }

View File

@ -39,7 +39,7 @@ class LCG64RandomSource(seed: Long = RandomSupport.generateUniqueSeed()) : LCG64
return Positional(nextLong()) return Positional(nextLong())
} }
class Positional(val seed: Long) : PositionalRandomFactory { class Positional(private val seed: Long) : PositionalRandomFactory {
override fun at(x: Int, y: Int, z: Int): RandomSource { override fun at(x: Int, y: Int, z: Int): RandomSource {
return LCG64RandomSource(Mth.getSeed(x, y, z).xor(seed)) return LCG64RandomSource(Mth.getSeed(x, y, z).xor(seed))
} }

View File

@ -31,7 +31,7 @@ class PCG32RandomSource(seed: Long = RandomSupport.generateUniqueSeed()) : PCG32
return Positional(nextLong()) return Positional(nextLong())
} }
class Positional(val seed: Long) : PositionalRandomFactory { class Positional(private val seed: Long) : PositionalRandomFactory {
override fun at(x: Int, y: Int, z: Int): RandomSource { override fun at(x: Int, y: Int, z: Int): RandomSource {
return PCG32RandomSource(Mth.getSeed(x, y, z).xor(seed)) return PCG32RandomSource(Mth.getSeed(x, y, z).xor(seed))
} }

View File

@ -55,10 +55,10 @@ class Xoshiro256Random : Xoshiro256StarStarRandom, IRandomSourceGenerator {
} }
class Positional( class Positional(
val s0: Long, private val s0: Long,
val s1: Long, private val s1: Long,
val s2: Long, private val s2: Long,
val s3: Long, private val s3: Long,
) : PositionalRandomFactory { ) : PositionalRandomFactory {
override fun at(x: Int, y: Int, z: Int): RandomSource { override fun at(x: Int, y: Int, z: Int): RandomSource {
val rng = LCG64RandomSource(Mth.getSeed(x, y, z)) val rng = LCG64RandomSource(Mth.getSeed(x, y, z))