API reference / @jsprismarine/worldgen / SampleContext
Class: SampleContext
Defined in: density/SampleContext.ts:134
The per-chunk state a compiled density function tree reads while sampling.
Java keeps the same split: the function tree is immutable and shared across chunks and threads, and everything mutable or chunk-specific lives here. The three overrides are the seams the world blender and the structure beard hook into.
Constructors
Constructor
new SampleContext():
SampleContext
Returns
SampleContext
Properties
beardifier
beardifier:
DensitySampler|undefined
Defined in: density/SampleContext.ts:150
Replaces beardifier, which is 0 where no structure pushes terrain around.
blendAlpha
blendAlpha:
DensitySampler|undefined
Defined in: density/SampleContext.ts:143
Replaces blend_alpha, which is 1 outside a blending region. The world blender sets it when a chunk borders terrain generated by an older version. This hook must be independent of y, matching Java's horizontal blending value, because density caches may share it down a column.
blendDensity
blendDensity: ((
x,y,z,density) =>number) |undefined
Defined in: density/SampleContext.ts:152
Post-processes blend_density, which is the identity outside a blending region.
blendOffset
blendOffset:
DensitySampler|undefined
Defined in: density/SampleContext.ts:148
Replaces blend_offset, which is 0 outside a blending region. This hook must be independent of y so a cache can safely reuse its value down a column.
interpolationBuffersEnabled
interpolationBuffersEnabled:
boolean=false
Defined in: density/SampleContext.ts:136
Enabled only while a caller walks complete interpolation cells in cell-major order.
interpolationCellVersions
interpolationCellVersions:
Uint32Array<ArrayBuffer>
Defined in: density/SampleContext.ts:178
The current interpolation-cell version per node id, used to invalidate y-stage entries.
interpolationCorners
interpolationCorners:
Float64Array<ArrayBuffer>
Defined in: density/SampleContext.ts:162
The eight corners of each interpolated node's current cell, eight doubles per node id, ordered x fastest, then y, then z.
Public and flat because the compiled closure reads it on every sample; SampleContext.interpolationCell is the only thing that may resize it, so a caller reads the field after that call rather than holding it across one.
interpolationXCache
interpolationXCache:
Float64Array<ArrayBuffer>
Defined in: density/SampleContext.ts:169
The current horizontal interpolation stage per node id: one x-in-cell key followed by the four x-interpolated corner values. The key is invalidated when SampleContext.interpolationCell moves to another cell.
interpolationYCache
interpolationYCache:
Float64Array<ArrayBuffer>
Defined in: density/SampleContext.ts:175
A 16-slot, direct-mapped cache for the y-interpolated corner pairs, 5 doubles per slot: cell version, x offset, y offset, and two values. Exact keys make collisions recompute.
Methods
cell()
cell(
id):CacheCell
Defined in: density/SampleContext.ts:190
Returns the memo slot a compiled cache node owns, creating it on first use.
Parameters
id
number
Returns
CacheCell
cornerCache()
cornerCache(
id):CornerCache
Defined in: density/SampleContext.ts:199
Returns the corner cache a compiled interpolated node fills, creating it on first use.
Parameters
id
number
Returns
interpolationBuffer()
interpolationBuffer(
id,valueCount):Float64Array
Defined in: density/SampleContext.ts:257
Returns a reusable cell output buffer, allocating it on the node's first cell.
Parameters
id
number
valueCount
number
Returns
Float64Array
interpolationBufferScratch()
interpolationBufferScratch(
id,valueCount):Float64Array
Defined in: density/SampleContext.ts:269
Returns reusable corner-stage values for filling an interpolation cell.
Parameters
id
number
valueCount
number
Returns
Float64Array
interpolationBufferValue()
interpolationBufferValue(
id,x,y,z,index):number|undefined
Defined in: density/SampleContext.ts:243
Returns a filled node buffer value when its cell origin still matches the query.
Parameters
id
number
x
number
y
number
z
number
index
number
Returns
number | undefined
interpolationCell()
interpolationCell(
id,x,y,z):boolean
Defined in: density/SampleContext.ts:214
Makes one interpolation cell current and says whether its corners are already in place.
Parameters
id
number
x
number
y
number
z
number
Returns
boolean
True when SampleContext.interpolationCorners still holds this cell's eight corners, false when the caller has to write them. A false answer has already recorded the new origin, so the next sample inside the cell gets a true one.
markInterpolationBufferFilled()
markInterpolationBufferFilled(
id,x,y,z):void
Defined in: density/SampleContext.ts:280
Records a cell origin only after its output buffer has been filled completely.
Parameters
id
number
x
number
y
number
z
number
Returns
void
reset()
reset():
void
Defined in: density/SampleContext.ts:294
Drops every memoized value.
A caller that walks more than one chunk with one context has to do this between them, or the corner caches keep serving the previous chunk's working set.
Returns
void