Files
misode.github.io/guides/density-functions.md
2022-05-26 03:58:44 +00:00

6.9 KiB

title, versions, tags
title versions tags
Density function types and their configuration
1.18.2
1.19
worldgen
noise
density

Density functions are used by the dimension generator to generate the terrain. They make up mathematical expressions that decide whether or not a block should be solid terrain.

Density functions

There are 3 ways to specify a density function. The first is simply as a constant number. The density function will always return that value

0.58

Another option is to reference a density function file. Vanilla has some builtin density functions, but you can create your own density functions in the worldgen/density_function folder.

"minecraft:overworld/base_3d_noise"

All the other density function types are defined as an object with a ftype field and optionally more fields.

{
  "type": "minecraft:noise",
  "noise": "minecraft:cave_entrance",
  "xz_scale": 0.75,
  "y_scale": 0.5
}

Types

abs

Calculates the absolute value of another density function.

  • fargument: The input density function

add

Adds two density functions together.

  • fargument1: The first density function
  • fargument2: The second density function

beardifier

Adds beards for structures ({#[1.18.2] see the fadapt_noise field in structures #}{#[1.19] see the fterrain_adaptation field in structures #}).

This density function has no extra fields

blend_alpha

This density function has no extra fields

blend_density

  • fargument: The input density function

blend_offset

This density function has no extra fields

cache_2d

Only computes the input density once for each column, at Y=0

  • fargument: The input density function

cache_all_in_cell

Used in combination with interpolated.

  • fargument: The input density function

cache_once

If this density function is referenced twice, it is only computed once per block position.

  • fargument: The input density function

clamp

Clamps the input between two values.

  • finput: The input density function
  • fmin: The lower bound
  • fmax: The upper bound

constant

A constant value. j{"type": "constant", "argument": 2} is equivalent to n2.

  • fargument: The constant number

cube

Cubes the input. (x^3)

  • fargument: The input density function

end_islands

This density function has no extra fields

flat_cache

Similar to cache_2d in that it only computes the input once for each column, but now at the first Y value that is requested.

half_negative

If the input is negative, returns half of the input. Otherwise returns the input. (x < 0 ? x/2 : x)

  • fargument: The input density function

interpolated

Computes the input density at each of the 8 corners of a cell and interpolates between them. The size of a cell if determined by size_horizontal * 4 and size_vertical * 4.

  • fargument: The input density function

max

Returns the maximum of two density functions.

  • fargument1: The first density function
  • fargument2: The second density function

min

Returns the minimum of two density functions.

  • fargument1: The first density function
  • fargument2: The second density function

mul

Multiplies two density functions.

  • fargument1: The first density function
  • fargument2: The second density function

noise

The noise density function samples a noise.

  • fnoise: A reference to a worldgen/noise file
  • fxz_scale: Scales the X and Z inputs before sampling
  • fy_scale: Scales the Y input before sampling

old_blended_noise

Uses a different kind of noise than noise.

  • fxz_scale
  • fy_scale
  • fxz_factor
  • fy_factor
  • fsmear_scale_multiplier

quarter_negative

If the input is negative, returns a quarter of the input. Otherwise returns the input. (x < 0 ? x/4 : x)

  • fargument: The input density function

range_choice

Computes the input value, and depending on that result returns one of two other density functions. Basically an if-then-else statement.

  • finput: The input density function
  • fmin_inclusive: The lower bound of the range
  • fmax_exclusive: The upper bound of the range
  • fwhen_in_range: Density function that will be returned when the input is inside the range
  • fwhen_out_of_range: Density function that will be returned When the input is outside the range

shift

Samples a noise at (x/4, y/4, z/4).

  • fargument: A reference to a worldgen/noise file

shift_a

Samples a noise at (x/4, 0, z/4).

  • fargument: A reference to a worldgen/noise file

shift_b

Samples a noise at (z/4, x/4, 0).

  • fargument: A reference to a worldgen/noise file

shifted_noise

Similar to noise, but first shifts the input coordinates.

  • fnoise: A reference to a worldgen/noise file
  • fxz_scale: Scales the X and Z inputs before sampling
  • fy_scale: Scales the Y input before sampling
  • fshift_x: Density function used to offset the X input
  • fshift_y: Density function used to offset the Y input
  • fshift_z: Density function used to offset the Z input

spline

Computes a spline. More information about splines will follow in a future guide.

  • fspline: The spline, can be either a number or an object:
    • fcoordinate: The density function that will be used for the locations
    • fpoints: List of points of the cubic spline, cannot be empty
      • flocation: Input value
      • fvalue: Output value, can be either a number or a spline object
      • fderivative: The slope at this point {#[1.18.2]
  • fmin_value: The minimum output value of the spline
  • fmax_value: The maximum output value of the spline #}

square

Squares the input. (x^2)

  • fargument: The input density function

squeeze

First clamps the input between -1 and 1, then transforms it using x/2 - x*x*x/24.

  • fargument: The input density function

{#[1.18.2]

terrain_shaper_spline

Computes a terrain shaper spline from the noise settings.

  • fspline: The terrain shaper spline to use. One of soffset, sfactor, or sjaggedness
  • fmin_value: The minimum output value of the spline
  • fmax_value: The maximum output value of the spline
  • fcontinentalness: The density function to use for the scontinents spline coordinate
  • ferosion: The density function to use for the serosion spline coordinate
  • fweirdness: The density function to use for the sweirdness spline coordinate #}

weird_scaled_sampler

  • frarity_value_mapper: One of stype_1 or stype_2
  • fnoise: A reference to a worldgen/noise file
  • finput: The input density function

y_clamped_gradient

Returns the Y position after mapping it to a range.

  • ffrom_y
  • fto_y
  • ffrom_value: The value to map ffrom_y to
  • fto_value: The value to map fto_y to