Density function

This feature is exclusive to Java Edition.
 

Density functions make up mathematical expressions to obtain a number from a position, stored as JSON files within a data pack in the path data/<namespace>/worldgen/density_function. They are referenced from the noise router in noise settings.

JSON format

A density function can be a constant number or an object.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type.
    • Other additional fields depend on the value of [String] type, described below.

If the [String] type is constant, a shorthand format is:

  • [Double]: A constant number. Value between −1000000.0 and 1000000.0 (both inclusive).

Maker functions

interpolated

Interpolates at each block in one cell based on the input density function value of some cells around. The size of each cell is size_horizontal * 4 and size_vertical * 4. Used often in combination with flat_cache.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, interpolated).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be interpolated.

flat_cache

Calculate the value per 4×4 column (Value at each block in one column is the same). And it is calculated only once per column, at Y=0. Used often in combination with interpolated.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, flat_cache).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.

cache_2d

Only computes the input density once per horizonal position.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, cache_2d).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.

cache_once

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

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, cache_once).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.

cache_all_in_cell

Used by the game onto final_density and should not be referenced in data packs.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, cache_all_in_cell).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.

Functions with one argument

abs

Calculates the absolute value of the input density function.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, abs).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

square

Squares the input. (x^2)

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, square).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

cube

Cubes the input (x^3).

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, cube).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

half_negative

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

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, half_negative).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

quarter_negative

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

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, quarter_negative).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

squeeze

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

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, squeeze).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.

Functions with two arguments

add

Adds two density functions together.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, add).
    • [String][Double][NBT Compound / JSON Object] argument1: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The first input of the calculation.
    • [String][Double][NBT Compound / JSON Object] argument2: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.

mul

Multiplies two inputs.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, mul).
    • [String][Double][NBT Compound / JSON Object] argument1: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The first input of the calculation.
    • [String][Double][NBT Compound / JSON Object] argument2: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.

min

Returns the minimum of two inputs.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, min).
    • [String][Double][NBT Compound / JSON Object] argument1: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The first input of the calculation.
    • [String][Double][NBT Compound / JSON Object] argument2: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.

max

Returns the maximum of two inputs.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, max).
    • [String][Double][NBT Compound / JSON Object] argument1: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The first input of the calculation.
    • [String][Double][NBT Compound / JSON Object] argument2: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.

Other density functions

blend_alpha

Used in vanilla for smooth transition to chunks generated in old versions.​

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, blend_alpha).

blend_offset

Used in vanilla for smooth transition to chunks generated in old versions.​

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, blend_offset).

blend_density

Used in vanilla for smooth transition to chunks generated in old versions.​

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, blend_density).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The desired density of new chunks.

beardifier

Adds beards for structures (see the terrain_adaptation field in structures). Its value is added to the final_density in noise setting by the game. Should not be referenced in data packs.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, beardifier).

old_blended_noise

Samples a legacy noise. ​

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, old_blended_noise).
    • [Double] xz_scale: Value between 0.001 and 1000.0 (both inclusive).
    • [Double] y_scale: Value between 0.001 and 1000.0 (both inclusive).
    • [Double] xz_factor: Value between 0.001 and 1000.0 (both inclusive).
    • [Double] y_factor: Value between 0.001 and 1000.0 (both inclusive).
    • [Double] smear_scale_multiplier: Value between 1.0 and 8.0 (both inclusive).

noise

Samples a noise.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, noise).
    • [String] noise: One noise (an [String] ID) — The noise to sample.
    • [Double] xz_scale: Scales the X and Z before sampling.
    • [Double] y_scale: Scales the Y before sampling.

end_islands

Samples at current position using a noise algorithm used for end islands. Its minimum value is −0.84375 and its maximum value is 0.5625.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, end_islands).

weird_scaled_sampler

According to the input value, scales and enhances (or weakens) some regions of the specified noise, and then returns the absolute value.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, weird_scaled_sampler).
    • [String] rarity_value_mapper: Can be type_1(The minimum scale is 0.75, and the maximum is 2.0)or type_2(The minimum scale is 0.5, and the maximum is 3.0.)
    • [String] noise: One noise (an [String] ID) — The noise to sample.
    • [String][Double][NBT Compound / JSON Object] input: The input density function. Can be an ID of a density function, or a density function in the form of a JSON object or a constant number.

shifted_noise

Similar to noise, but first shifts the input coordinates.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, shifted_noise).
    • [String] noise: One noise (an [String] ID) — The noise to sample.
    • [Double] xz_scale: Scales the X and Z before sampling.
    • [Double] y_scale: Scales the Y before sampling.
    • [String][Double][NBT Compound / JSON Object] shift_x: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — offset of the position in the X direction.
    • [String][Double][NBT Compound / JSON Object] shift_y: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — offset of the position in the Y direction.
    • [String][Double][NBT Compound / JSON Object] shift_z: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — offset of the position in the Z direction.

range_choice

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

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, range_choice).
    • [String][Double][NBT Compound / JSON Object] input: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The value to compare
    • [Double] min_inclusive: The lower bound of the range. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [Double] max_exclusive: The upper bound of the range. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [String][Double][NBT Compound / JSON Object] when_in_range: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — Used when the input is inside the range.
    • [String][Double][NBT Compound / JSON Object] when_out_of_range: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — Used when the input is outside the range.

shift_a

Samples a noise at (x/4, 0, z/4), then multiplies it by 4.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, shift_a).
    • [String] argument: One noise (an [String] ID) — The noise to sample.

shift_b

Samples a noise at (z/4, x/4, 0), then multiplies it by 4.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, shift_b).
    • [String] argument: One noise (an [String] ID) — The noise to sample.

shift

Samples a noise at (x/4, y/4, z/4), then multiplies it by 4.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, shift).
    • [String] argument: One noise (an [String] ID) — The noise to sample.

clamp

Clamps the input between two values.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, clamp).
    • [Double][NBT Compound / JSON Object] input: One density function (a new [Double][NBT Compound / JSON Object] density function definition, an [String]ID is not allowed here[1]) — The input to clamp.
    • [Double] min: The lower bound. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [Double] max: The upper bound. Value between −1000000.0 and 1000000.0 (both inclusive).

spline

Computes a cubic spline.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, spline).
    • [Float][NBT Compound / JSON Object] spline: The spline. Can be either a number or an object.
      • [String][Double][NBT Compound / JSON Object] coordinate: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — Input determining the location on the spline.
      • [NBT List / JSON Array] points: (Cannot be empty) List of points of the cubic spline.
        • [NBT Compound / JSON Object]: A point of the cubic spline.
          • [Float] location: The location of this point.
          • [Float][NBT Compound / JSON Object] value: The value of this point. Can be either a number or a spline object.
          • [Float] derivative: The slope at this point.

constant

A constant value.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, constant).
    • [Double] argument: A constant value. Value between −1000000.0 and 1000000.0 (both inclusive).

y_clamped_gradient

Clamps the Y coordinate between from_y and to_y and then linearly maps it to a range.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, y_clamped_gradient).
    • [Int] from_y: The value to be mapped to from_value. Value between −4064 and 4062 (both inclusive).
    • [Int] to_y: The value to be mapped to to_value. Value between −4064 and 4062 (both inclusive).
    • [Double] from_value: The value to map from_y to. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [Double] to_value: The value to map to_y to. Value between −1000000.0 and 1000000.0 (both inclusive).

Removed density functions

BlockSprite rose.png: Sprite image for rose in Minecraft
This section describes content that has been removed from the game.
 
This feature was present in earlier versions of Minecraft, but has since been removed.

slide

Removed in 22w12a

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, slide).
    • [String][Double][NBT Compound / JSON Object] argument: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)

The legacy "spline"

Removed in 22w11a

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, spline).
    • [Float][NBT Compound / JSON Object] spline: The spline. Can be either a number or an object.
      • [String][Double][NBT Compound / JSON Object] coordinate: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — Input determining the location on the spline.
      • [NBT List / JSON Array] points: (Cannot be empty) List of points of the cubic spline.
        • [Float] location: The location of this point.
        • [Float][NBT Compound / JSON Object] value: The value of this point. Can be either a number or a spline object.
        • [Float] derivative: The slope at this point.
    • [Double] min_value: The min value of the output. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [Double] max_value: The max value of the output. Value between −1000000.0 and 1000000.0 (both inclusive).

terrain_shaper_spline

Removed in 22w11a

Calculate the spline from the noise settings.

  • [NBT Compound / JSON Object]: Root object.
    • [String] type: The ID of the density function type (in this case, terrain_shaper_spline).
    • [String] spline: Can be offset, factor, orjaggedness.
    • [Double] min_value: The min value of the output. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [Double] max_value: The max value of the output. Value between −1000000.0 and 1000000.0 (both inclusive).
    • [String][Double][NBT Compound / JSON Object] continentalness: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
    • [String][Double][NBT Compound / JSON Object] erosion: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
    • [String][Double][NBT Compound / JSON Object] weirdness: One (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)

History

Java Edition
1.18.2pre1Added density functions: abs, add, beardifier, blend_alpha, blend_density, blend_offset, cache_2d, cache_all_in_cell, cache_once, clamp, constant, cube, end_islands, flat_cache, half_negative, interpolated, max, min, mul, noise, old_blended_noise, quarter_negative, range_choice, shift, shift_a, shift_b, shifted_noise, slide, square, squeeze, terrain_shaper_spline, weird_scaled_sampler, and y_clamped_gradient.
pre2Added density function spline.
1.1922w11aRemoved density function terrain_shaper_spline.
Removed min_value and max_value fields in spline.
22w12aRemoved density function slide. Instead a combination of add, mul, and y_clamped_gradient is used to achieve the same result.
Added fields to old_blended_noise density function: xz_scale, y_scale, xz_factor, y_factor, and smear_scale_multiplier.

Issues

Issues relating to "Density function" are maintained on the bug tracker. Issues should be reported and viewed there.

References

External links

Navigation