Use PCG as random source in Enormous Placement
This commit is contained in:
parent
3ea9a7f386
commit
d06c32aec2
@ -3,10 +3,9 @@ package ru.dbotthepony.mc.otm.worldgen.placement
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.github.benmanes.caffeine.cache.Scheduler
|
||||
import com.mojang.serialization.Codec
|
||||
import com.mojang.serialization.DataResult
|
||||
import com.mojang.serialization.MapCodec
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import it.unimi.dsi.fastutil.HashCommon
|
||||
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||
import net.minecraft.Util
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.SectionPos
|
||||
@ -14,10 +13,11 @@ import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.level.ChunkPos
|
||||
import net.minecraft.world.level.levelgen.placement.PlacementContext
|
||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier
|
||||
import ru.dbotthepony.mc.otm.core.util.CMWCRandom
|
||||
import ru.dbotthepony.mc.otm.core.util.Xoshiro256SSRandom
|
||||
import ru.dbotthepony.mc.otm.data.codec.inRange
|
||||
import ru.dbotthepony.kommons.util.XXHash64
|
||||
import ru.dbotthepony.mc.otm.core.util.PCG32RandomSource
|
||||
import ru.dbotthepony.mc.otm.data.codec.minRange
|
||||
import ru.dbotthepony.mc.otm.worldgen.placement.AbstractEnormousPlacement.Parameters
|
||||
import java.io.DataOutputStream
|
||||
import java.time.Duration
|
||||
import java.util.stream.Stream
|
||||
import kotlin.math.sqrt
|
||||
@ -73,7 +73,18 @@ abstract class AbstractEnormousPlacement(val parameters: Parameters) : Placement
|
||||
.build<ChunkPos, GeneratedChunk>()
|
||||
|
||||
private fun computeChunk(context: PlacementContext, pos: ChunkPos): GeneratedChunk {
|
||||
val random = Xoshiro256SSRandom(context.level.seed, parameters.seedMix, pos.x.toLong(), pos.z.toLong())
|
||||
val bytes = FastByteArrayOutputStream()
|
||||
val dataStream = DataOutputStream(bytes)
|
||||
|
||||
dataStream.writeLong(context.level.seed)
|
||||
dataStream.writeLong(parameters.seedMix)
|
||||
dataStream.writeInt(pos.x)
|
||||
dataStream.writeInt(pos.z)
|
||||
|
||||
val hash = XXHash64()
|
||||
hash.update(bytes.array, 0, bytes.length)
|
||||
|
||||
val random = PCG32RandomSource(hash.digestAsLong())
|
||||
var stream = Stream.of(BlockPos(pos.minBlockX, 0, pos.minBlockZ))
|
||||
parameters.placementModifiers.forEach { modifier -> stream = stream.flatMap { modifier.getPositions(context, random, it).sequential() } }
|
||||
return GeneratedChunk(stream.flatMap { getPositions(it, random) })
|
||||
|
Loading…
Reference in New Issue
Block a user