Compare commits

..

No commits in common. "45181c9e55641ce130fe0ffc43a0f39f224da71e" and "01d3cbf7b214943cbca93c0258eb80a4f9aad108" have entirely different histories.

2 changed files with 9 additions and 3 deletions

View File

@ -2,12 +2,15 @@ package ru.dbotthepony.mc.otm.core.util
import net.minecraft.util.Mth import net.minecraft.util.Mth
import net.minecraft.util.RandomSource import net.minecraft.util.RandomSource
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.GJRAND64Random import ru.dbotthepony.kommons.random.GJRAND64Random
import java.lang.StringBuilder import java.lang.StringBuilder
class GJRAND64RandomSource : GJRAND64Random, IRandomSourceGenerator { class GJRAND64RandomSource : GJRAND64Random, IRandomSourceGenerator {
private val gaussian = MarsagliaPolarGaussian(this)
constructor() : super(RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed()) constructor() : super(RandomSupport.generateUniqueSeed(), RandomSupport.generateUniqueSeed())
constructor(seed: Long) : super(seed) constructor(seed: Long) : super(seed)
constructor(seed0: Long, seed1: Long) : super(seed0, seed1) constructor(seed0: Long, seed1: Long) : super(seed0, seed1)
@ -16,6 +19,10 @@ class GJRAND64RandomSource : GJRAND64Random, IRandomSourceGenerator {
return nextLong().ushr(32).toInt() return nextLong().ushr(32).toInt()
} }
override fun nextGaussian(): Double {
return gaussian.nextGaussian()
}
override fun fork(): RandomSource { override fun fork(): RandomSource {
return GJRAND64RandomSource(nextLong(), nextLong()) return GJRAND64RandomSource(nextLong(), nextLong())
} }
@ -26,6 +33,7 @@ class GJRAND64RandomSource : GJRAND64Random, IRandomSourceGenerator {
override fun setSeed(seed: Long) { override fun setSeed(seed: Long) {
reinitialize(seed) reinitialize(seed)
gaussian.reset()
} }
class Positional(private val seed0: Long, private val seed1: Long) : PositionalRandomFactory { class Positional(private val seed0: Long, private val seed1: Long) : PositionalRandomFactory {

View File

@ -26,7 +26,5 @@ interface IRandomSourceGenerator : RandomSource, RandomGenerator {
return super.nextDouble() return super.nextDouble()
} }
override fun nextGaussian(): Double { override fun nextGaussian(): Double
return super.nextGaussian()
}
} }