Density function
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
[edit | edit source]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).
Marker functions
[edit | edit source]interpolated
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be interpolated.
- [String] type: The ID of the density function type (in this case,
flat_cache
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.
- [String] type: The ID of the density function type (in this case,
cache_2d
[edit | edit source]Only computes the input density once per horizontal 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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.
- [String] type: The ID of the density function type (in this case,
cache_once
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.
- [String] type: The ID of the density function type (in this case,
cache_all_in_cell
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input to be cached.
- [String] type: The ID of the density function type (in this case,
Mapped density functions
[edit | edit source]abs
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
square
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
cube
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
half_negative
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
quarter_negative
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
squeeze
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
invert
[edit | edit source]Inverts the input (1/x).
- [NBT Compound / JSON Object]: Root object.
- [String] type: The ID of the density function type (in this case,
invert). - [String][Double][NBT Compound / JSON Object] argument: One density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The input of the calculation.
- [String] type: The ID of the density function type (in this case,
Functions with two arguments
[edit | edit source]add
[edit | edit source]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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.
- [String] type: The ID of the density function type (in this case,
mul
[edit | edit source]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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.
- [String] type: The ID of the density function type (in this case,
min
[edit | edit source]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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.
- [String] type: The ID of the density function type (in this case,
max
[edit | edit source]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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The second input of the calculation.
- [String] type: The ID of the density function type (in this case,
Other density functions
[edit | edit source]blend_alpha
[edit | edit source]Used in vanilla for smooth transition to chunks generated in old versions.[more information needed]
- [NBT Compound / JSON Object]: Root object.
- [String] type: The ID of the density function type (in this case,
blend_alpha).
- [String] type: The ID of the density function type (in this case,
blend_offset
[edit | edit source]Used in vanilla for smooth transition to chunks generated in old versions.[more information needed]
- [NBT Compound / JSON Object]: Root object.
- [String] type: The ID of the density function type (in this case,
blend_offset).
- [String] type: The ID of the density function type (in this case,
blend_density
[edit | edit source]Used in vanilla for smooth transition to chunks generated in old versions.[more information needed]
- [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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The desired density of new chunks.
- [String] type: The ID of the density function type (in this case,
beardifier
[edit | edit source]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).
- [String] type: The ID of the density function type (in this case,
old_blended_noise
[edit | edit source]Samples a legacy noise. [more information needed]
- [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).
- [String] type: The ID of the density function type (in this case,
noise
[edit | edit source]Samples a noise.
end_islands
[edit | edit source]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).
- [String] type: The ID of the density function type (in this case,
weird_scaled_sampler
[edit | edit source]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)ortype_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.
- [String] type: The ID of the density function type (in this case,
shifted_noise
[edit | edit source]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 density function (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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — offset of the position in the Z direction.
- [String] type: The ID of the density function type (in this case,
range_choice
[edit | edit source]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 density function (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 density function (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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — Used when the input is outside the range.
- [String] type: The ID of the density function type (in this case,
shift_a
[edit | edit source]Samples a noise at (x/4, 0, z/4), then multiplies it by 4.
shift_b
[edit | edit source]Samples a noise at (z/4, x/4, 0), then multiplies it by 4.
shift
[edit | edit source]Samples a noise at (x/4, y/4, z/4), then multiplies it by 4.
clamp
[edit | edit source]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).
- [String] type: The ID of the density function type (in this case,
spline
[edit | edit source]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 density function (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.
- [NBT Compound / JSON Object]: A point of the cubic spline.
- [String] type: The ID of the density function type (in this case,
constant
[edit | edit source]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).
- [String] type: The ID of the density function type (in this case,
y_clamped_gradient
[edit | edit source]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_yto. Value between −1000000.0 and 1000000.0 (both inclusive). - [Double] to_value: The value to map
to_yto. Value between −1000000.0 and 1000000.0 (both inclusive).
- [String] type: The ID of the density function type (in this case,
find_top_surface
[edit | edit source]Scans through a column of an input density and returns the topmost y-level that is above 0. If no such position exists withing the bounds, the [Int] lower_bound is returned.
- [NBT Compound / JSON Object]: Root object.
- [String] type: The ID of the density function type (in this case,
find_top_surface). - [String][Double][NBT Compound / JSON Object] density: One density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The density function to scan.
- [String][Double][NBT Compound / JSON Object] upper_bound: One density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition) — The y-level to start the scan at. Usually a 2D density function.
- [Int] lower_bound: The y-level to stop the scan.
- [Int] cell_height: The resolution of the scan. E.g. if set to
4, then only every 4th block is checked.
- [String] type: The ID of the density function type (in this case,
Removed density functions
[edit | edit source]slide
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
- [String] type: The ID of the density function type (in this case,
The legacy "spline"
[edit | edit source]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 density function (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).
- [String] type: The ID of the density function type (in this case,
terrain_shaper_spline
[edit | edit source]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 density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
- [String][Double][NBT Compound / JSON Object] erosion: One density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
- [String][Double][NBT Compound / JSON Object] weirdness: One density function (an [String] ID, or a new [Double][NBT Compound / JSON Object] density function definition)
- [String] type: The ID of the density function type (in this case,
History
[edit | edit source]| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.18.2 | pre1 | Added 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. | |||||
| pre2 | Added density function spline. | ||||||
| 1.19 | 22w11a | Removed density function terrain_shaper_spline. | |||||
Removed min_value and max_value fields in spline. | |||||||
| 22w12a | Removed 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. | |||||||
| 1.21.9 | 25w31a | Added minecraft:find_top_surface | |||||
Added minecraft:invert | |||||||
Issues
[edit | edit source]Issues relating to "Density function" are maintained on the bug tracker. Issues should be reported and viewed there.