API reference / @jsprismarine/features / WorldgenRandom
Class: WorldgenRandom
Defined in: placement/WorldgenRandom.ts:37
Java Edition's WorldgenRandom: a reseedable stream, plus the four seed derivations world generation keys off.
It is not simply one of @jsprismarine/worldgen's two sources. Java's class extends LegacyRandomSource and overrides only next(bits), so every derived draw -- nextInt, nextFloat, nextDouble, nextGaussian -- uses java.util.Random's formulas over a Xoroshiro bit stream. Handing a feature a plain XoroshiroRandomSource produces different numbers from the first float onward, which is why this class exists rather than a helper.
The seed derivations matter more than they look. Every feature placed in a chunk draws from a stream seeded by the chunk's population seed, the feature's index in the flattened per-step list and its decoration step. That is what makes a world reproducible: two servers that agree on the seed, the chunk and the feature list place the same blocks, in any order, on any number of threads.
Implements
Constructors
Constructor
new WorldgenRandom(
seed?,algorithm?):WorldgenRandom
Defined in: placement/WorldgenRandom.ts:50
Parameters
seed?
bigint = 0n
The initial seed. The chunk generator's value is discarded by the first setDecorationSeed, so it only matters for a stream used directly.
algorithm?
WorldgenRandomAlgorithm = 'xoroshiro'
The backing generator. Defaults to Xoroshiro, which is what ChunkGenerator.applyBiomeDecoration builds.
Returns
WorldgenRandom
Methods
consumeCount()
consumeCount(
rounds):void
Defined in: placement/WorldgenRandom.ts:208
Advances the stream by rounds draws without returning them.
Parameters
rounds
number
Returns
void
Implementation of
fork()
fork():
RandomSource
Defined in: placement/WorldgenRandom.ts:213
Returns an independent stream seeded from this one, advancing this one.
Returns
Implementation of
forkPositional()
forkPositional():
PositionalRandomFactory
Defined in: placement/WorldgenRandom.ts:218
Returns a positional factory seeded from this stream, advancing it.
Returns
Implementation of
next()
next(
bits):number
Defined in: placement/WorldgenRandom.ts:150
Returns the top bits bits of the backing stream, as Java's next(int) does.
Parameters
bits
number
Returns
number
nextBoolean()
nextBoolean():
boolean
Defined in: placement/WorldgenRandom.ts:185
Returns the next boolean, taken from one bit of the stream.
Returns
boolean
Implementation of
nextDouble()
nextDouble():
number
Defined in: placement/WorldgenRandom.ts:195
Returns the next value in [0, 1) with 53 bits of precision.
Returns
number
Implementation of
nextFloat()
nextFloat():
number
Defined in: placement/WorldgenRandom.ts:190
Returns the next value in [0, 1) with 24 bits of precision.
Returns
number
Implementation of
nextGaussian()
nextGaussian():
number
Defined in: placement/WorldgenRandom.ts:203
Returns the next normally distributed value with mean 0 and standard deviation 1.
Returns
number
Implementation of
nextInt()
nextInt():
number
Defined in: placement/WorldgenRandom.ts:157
Returns the next 32-bit signed integer, with every value equally likely.
Returns
number
Implementation of
nextIntBounded()
nextIntBounded(
bound):number
Defined in: placement/WorldgenRandom.ts:162
Returns the next integer in [0, bound).
Parameters
bound
number
Returns
number
Throws
When bound is not positive, as Java does.
Implementation of
nextLong()
nextLong():
bigint
Defined in: placement/WorldgenRandom.ts:178
Returns the next 64-bit signed integer.
Returns
bigint
Implementation of
restoreState()
restoreState(
state):void
Defined in: placement/WorldgenRandom.ts:73
Restores a state produced by saveState, including Java's cached Gaussian value.
Parameters
state
unknown
Returns
void
saveState()
saveState():
WorldgenRandomState
Defined in: placement/WorldgenRandom.ts:60
Captures the backing stream and Java's separately cached Gaussian value.
Returns
setDecorationSeed()
setDecorationSeed(
levelSeed,minBlockX,minBlockZ):bigint
Defined in: placement/WorldgenRandom.ts:114
Derives and applies a chunk's population seed, then returns it.
Parameters
levelSeed
bigint
The world seed.
minBlockX
number
The x of the chunk's lowest-numbered block, not its chunk coordinate.
minBlockZ
number
The z of the chunk's lowest-numbered block.
Returns
bigint
setFeatureSeed()
setFeatureSeed(
populationSeed,index,step):void
Defined in: placement/WorldgenRandom.ts:130
Applies the stream one placed feature draws from.
Parameters
populationSeed
bigint
The value setDecorationSeed returned.
index
number
The feature's index within the flattened per-step feature list.
step
number
The decoration step's ordinal, 0 through 10.
Returns
void
setLargeFeatureSeed()
setLargeFeatureSeed(
baseSeed,chunkX,chunkZ):void
Defined in: placement/WorldgenRandom.ts:135
Applies the stream a structure start draws from, keyed by chunk.
Parameters
baseSeed
bigint
chunkX
number
chunkZ
number
Returns
void
setLargeFeatureWithSalt()
setLargeFeatureWithSalt(
levelSeed,regionX,regionZ,salt):void
Defined in: placement/WorldgenRandom.ts:143
Applies the salted stream the region-based structure placements draw from.
Parameters
levelSeed
bigint
regionX
number
regionZ
number
salt
number
Returns
void
setSeed()
setSeed(
seed):void
Defined in: placement/WorldgenRandom.ts:103
Restarts the stream from a seed, as Java's setSeed does.
Parameters
seed
bigint
Returns
void