Skip to content

API reference / @jsprismarine/worldgen / MaterialRuleContext

Class: MaterialRuleContext ​

Defined in: surface/MaterialRuleContext.ts:53

The position a compiled material rule is looking at, and everything it can ask about that position.

The surface pass walks a column downward and updates the context in two steps: once per column through updateXZ and once per block through updateY. Conditions that only depend on the column cache their answer against the first counter and conditions that depend on the block cache against the second, which is why one chunk evaluates the surface noise 256 times instead of 98304 times.

Constructors ​

Constructor ​

new MaterialRuleContext(options): MaterialRuleContext

Defined in: surface/MaterialRuleContext.ts:97

Parameters ​

options ​

MaterialRuleContextOptions

Returns ​

MaterialRuleContext

Properties ​

blockX ​

blockX: number = 0

Defined in: surface/MaterialRuleContext.ts:55

The x coordinate of the column being built.


blockY ​

blockY: number = 0

Defined in: surface/MaterialRuleContext.ts:65

The y coordinate of the block being built.


blockZ ​

blockZ: number = 0

Defined in: surface/MaterialRuleContext.ts:57

The z coordinate of the column being built.


generationContext ​

readonly generationContext: WorldGenerationContext

Defined in: surface/MaterialRuleContext.ts:80

The dimension extent a vertical anchor resolves against.


possibleBiomes ​

readonly possibleBiomes: ReadonlySet<string> | undefined

Defined in: surface/MaterialRuleContext.ts:78

Every biome the chunk can hold, or undefined when the caller did not narrow it.


sampleContext ​

readonly sampleContext: SampleContext

Defined in: surface/MaterialRuleContext.ts:82

The memo slots the compiled density functions share.


stoneDepthAbove ​

stoneDepthAbove: number = 0

Defined in: surface/MaterialRuleContext.ts:69

How many solid blocks sit between this one and the air above it, counting this one.


stoneDepthBelow ​

stoneDepthBelow: number = 0

Defined in: surface/MaterialRuleContext.ts:71

How many solid blocks sit between this one and the opening below it, counting this one.


surfaceDepth ​

surfaceDepth: number = 0

Defined in: surface/MaterialRuleContext.ts:63

The randomized thickness of the column's surface layer.


surfaceGradientX ​

surfaceGradientX: number = 0

Defined in: surface/MaterialRuleContext.ts:59

How much the terrain height changes across the column in x.


surfaceGradientZ ​

surfaceGradientZ: number = 0

Defined in: surface/MaterialRuleContext.ts:61

How much the terrain height changes across the column in z.


updateCountXZ ​

updateCountXZ: number = 0

Defined in: surface/MaterialRuleContext.ts:73

Counts updateXZ calls, which the per-column caches compare against.


updateCountY ​

updateCountY: number = 0

Defined in: surface/MaterialRuleContext.ts:75

Counts updateXZ and updateY calls, which the per-block caches use.


waterHeight ​

waterHeight: number = Number.NEGATIVE_INFINITY

Defined in: surface/MaterialRuleContext.ts:67

The y of the first block above the fluid covering this position, or -Infinity.

Accessors ​

seaLevel ​

Get Signature ​

get seaLevel(): number

Defined in: surface/MaterialRuleContext.ts:130

The dimension's sea level.

Returns ​

number

Methods ​

densitySampler() ​

densitySampler(node): DensitySampler

Defined in: surface/MaterialRuleContext.ts:193

Compiles a density function against this world's seed.

Parameters ​

node ​

DensityFunctionNode

Returns ​

DensitySampler


getBand() ​

getBand(x, y, z): string

Defined in: surface/MaterialRuleContext.ts:203

The terracotta band of a badlands column at one position.

Parameters ​

x ​

number

y ​

number

z ​

number

Returns ​

string


getBiome() ​

getBiome(): string

Defined in: surface/MaterialRuleContext.ts:135

The biome at the current position, looked up once per block.

Returns ​

string


getMinSurfaceLevel() ​

getMinSurfaceLevel(): number

Defined in: surface/MaterialRuleContext.ts:155

The lowest y the surface pass treats as "near the surface", sampled once per column.

This is the preliminary surface the terrain router predicted, raised by the column's surface depth and lowered by eight blocks of slack.

Returns ​

number


getSurfaceSecondary() ​

getSurfaceSecondary(): number

Defined in: surface/MaterialRuleContext.ts:141

The secondary surface noise of the current column, sampled once per column.

Returns ​

number


isColdEnoughToSnow() ​

isColdEnoughToSnow(): boolean

Defined in: surface/MaterialRuleContext.ts:166

Whether the current position is cold enough for snow, which needs the biome's climate.

Returns ​

boolean


randomFactory() ​

randomFactory(name): PositionalRandomFactory

Defined in: surface/MaterialRuleContext.ts:188

The positional random factory a named rule draws from.

Parameters ​

name ​

string

Returns ​

PositionalRandomFactory


resolveAnchorY() ​

resolveAnchorY(anchor): number

Defined in: surface/MaterialRuleContext.ts:198

Resolves a vertical anchor against the dimension extent.

Parameters ​

anchor ​

VerticalAnchor

Returns ​

number


sampleNoise() ​

sampleNoise(id, is3d): number

Defined in: surface/MaterialRuleContext.ts:177

Samples a named noise at the current column or the current block.

Parameters ​

id ​

string

is3d ​

boolean

Returns ​

number


updateXZ() ​

updateXZ(blockX, blockZ, surfaceGradientX, surfaceGradientZ): void

Defined in: surface/MaterialRuleContext.ts:109

Moves the context to a new column and recomputes its surface depth.

Parameters ​

blockX ​

number

blockZ ​

number

surfaceGradientX ​

number

surfaceGradientZ ​

number

Returns ​

void


updateY() ​

updateY(stoneDepthAbove, stoneDepthBelow, waterHeight, blockY): void

Defined in: surface/MaterialRuleContext.ts:120

Moves the context to a new block of the current column.

Parameters ​

stoneDepthAbove ​

number

stoneDepthBelow ​

number

waterHeight ​

number

blockY ​

number

Returns ​

void