API reference / @jsprismarine/worldgen / RandomState
Class: RandomState
Defined in: RandomState.ts:32
Everything one world seed fixes: the positional randoms, the seeded noise instances and the compiled density functions.
A RandomState is immutable once built and safe to share across chunks. The mutable per-chunk state lives in the SampleContext instances it hands out.
Constructors
Constructor
new RandomState(
data,seed,settings,compilerOptions?):RandomState
Defined in: RandomState.ts:40
Parameters
data
seed
bigint
The 64-bit world seed.
settings
The settings whose legacy_random_source flag chooses the generator.
compilerOptions?
DensityFunctionCompilerOptions = {}
Optional compiler experiment flags, which leave the closure implementation as default.
Returns
RandomState
Properties
random
readonlyrandom:PositionalRandomFactory
Defined in: RandomState.ts:34
The positional factory every noise and feature stage derives its randomness from.
seed
readonlyseed:bigint
Defined in: RandomState.ts:43
The 64-bit world seed.
settings
readonlysettings:NoiseGeneratorSettings
Defined in: RandomState.ts:45
The settings whose legacy_random_source flag chooses the generator.
Accessors
closureFallbackCount
Get Signature
get closureFallbackCount():
number
Defined in: RandomState.ts:164
Density nodes that remained on the closure compiler.
Returns
number
generatedFunctionBytes
Get Signature
get generatedFunctionBytes():
number
Defined in: RandomState.ts:159
Source characters emitted by the optional density code generator.
Returns
number
generatedFunctionCount
Get Signature
get generatedFunctionCount():
number
Defined in: RandomState.ts:154
How many density samplers the optional code generator emitted.
Returns
number
interpolationCellSize
Get Signature
get interpolationCellSize():
InterpolationCellSize|undefined
Defined in: RandomState.ts:127
The cell the interpolated nodes compiled so far hold their corners still across, or undefined when none of them has been compiled yet.
This is a hint for a caller choosing a visiting order, not part of any result: a sample answers the same whatever order it is asked in.
Deprecated
It covers every tree compiled on this state, so compiling another function first, such as the surface pass's chunk_surface_level, makes it smaller. Pass the tree being walked to RandomState.interpolationCellSizeOf.
Returns
InterpolationCellSize | undefined
Methods
createContext()
createContext():
SampleContext
Defined in: RandomState.ts:169
Creates the per-chunk mutable state a sampler reads, with every memo slot empty.
Returns
interpolationCellSizeOf()
interpolationCellSizeOf(
node):InterpolationCellSize|undefined
Defined in: RandomState.ts:138
The cell the interpolated nodes reachable from one tree hold their corners still across, or undefined when it holds none.
A hint for a caller choosing a visiting order, like RandomState.interpolationCellSize, but fixed by the tree alone, whatever else this state has compiled.
Parameters
node
Returns
InterpolationCellSize | undefined
isYIndependent()
isYIndependent(
node):boolean
Defined in: RandomState.ts:112
Whether a density tree's proven input axes exclude y.
Parameters
node
Returns
boolean
noise()
noise(
id):Noise
Defined in: RandomState.ts:71
Returns the seeded noise instance for an identifier, building it on first use.
The nether's temperature and vegetation noises take the pre-1.18 path, seeded from a legacy random at a fixed offset from the world seed rather than from a hashed name.
Parameters
id
string
Returns
randomFactory()
randomFactory(
name):PositionalRandomFactory
Defined in: RandomState.ts:88
Returns the positional factory keyed by a name, such as minecraft:aquifer.
Parameters
name
string
Returns
sampler()
sampler(
node):DensitySampler
Defined in: RandomState.ts:97
Compiles a density function tree against this seed, reusing earlier compilations.
Parameters
node
Returns
sampleUncached()
sampleUncached(
node,x,y,z):number
Defined in: RandomState.ts:179
Samples one density function at one position with no caching between calls.
This is the debug path Java exposes as sampleBlockValueUncached; chunk generation goes through import('./chunk/ChunkSampler').ChunkSampler instead.
Parameters
node
x
number
y
number
z
number
Returns
number
volumeSampler()
volumeSampler(
node):DensityVolumeEvaluator
Defined in: RandomState.ts:107
Compiles an opt-in volume evaluator for one density function tree.
The plan is cached by this state, but each returned evaluator owns a separate mutable workspace and must not serve overlapping calls.