Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Density function: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Sync: updated from Minecraft
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
Line 150: Line 150:
** {{nbt|string}}{{nbt|double}}{{nbt|compound|input}}: Density Function to round.
** {{nbt|string}}{{nbt|double}}{{nbt|compound|input}}: Density Function to round.
** {{nbt|string}}{{nbt|double}}{{nbt|compound|multiple}}: The output will be rounded to an integer multiple of the value returned by this Density Function. If not specified, defaults to a constant 1.
** {{nbt|string}}{{nbt|double}}{{nbt|compound|multiple}}: The output will be rounded to an integer multiple of the value returned by this Density Function. If not specified, defaults to a constant 1.
</div>
=== {{cd|clamp}} ===
Clamps the input between two values.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>clamp</code>).
** {{nbt|string}}{{nbt|double}}{{nbt|compound|input}}: One density function &mdash; The input to clamp.
** {{Nbt|double|min}}: The lower bound. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|max}}: The upper bound. Value between −1000000.0 and 1000000.0 (both inclusive).
</div>
</div>


Line 307: Line 317:
== Mapped density functions ==
== Mapped density functions ==
These density functions map a set of values onto another set of values.
These density functions map a set of values onto another set of values.
=== {{cd|clamp}} ===
Clamps the input between two values.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>clamp</code>).
** {{Nbt|double}}{{Nbt|compound|input}}: One '''density function''' (a new {{Nbt|double}}{{Nbt|compound}} density function definition, an {{Nbt|string|}}[[Minecraft:resource location|ID]] is not allowed here<ref>{{cite bug|MC|252814|Clamp density function takes a direct input and doesn't allow a reference|date=June 11, 2022}}</ref>) &mdash; The input to clamp.
** {{Nbt|double|min}}: The lower bound. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|max}}: The upper bound. Value between −1000000.0 and 1000000.0 (both inclusive).
</div>


=== {{cd|gradient}} ===
=== {{cd|gradient}} ===
[[File:Gradient tiling.png|thumb|Demonstration of the different tiling options for the {{cd|gradient}} density function{{upcoming|JE 26.3}}, using both an input and output range of -1 to 1.]]
[[File:Gradient tiling.png|thumb|Demonstration of the different tiling options for the {{cd|gradient}} density function{{upcoming|JE 26.3}}, using both an input range of -100 to 100 and an output range of -1 to 1.]]
Clamps the given coordinate and maps the gradient to a range.{{upcoming|JE 26.3}}
Clamps the given coordinate and maps the gradient to a range.{{upcoming|JE 26.3}}
<div class="treeview">
<div class="treeview">
Line 456: Line 456:


=== {{cd|distance_to_point}} ===
=== {{cd|distance_to_point}} ===
[[File:Distance to point options.png|thumb|Demonstration of the different metric options for the {{cd|distance_to_point}} density function{{upcoming|JE 26.3}}, using the distance from the point (0, 0).]]
Computes the distance to a fixed point using the specified distance function.{{upcoming|JE 26.3}}
Computes the distance to a fixed point using the specified distance function.{{upcoming|JE 26.3}}


Line 581: Line 582:
Added fields to {{cd|old_blended_noise}} density function: xz_scale, y_scale, xz_factor, y_factor, and smear_scale_multiplier.}}
Added fields to {{cd|old_blended_noise}} density function: xz_scale, y_scale, xz_factor, y_factor, and smear_scale_multiplier.}}
|{{HistoryLine||1.21.9|dev=25w31a|Added density functions {{cd|minecraft:find_top_surface}} and {{cd|minecraft:invert}}.}}
|{{HistoryLine||1.21.9|dev=25w31a|Added density functions {{cd|minecraft:find_top_surface}} and {{cd|minecraft:invert}}.}}
|{{HistoryLine||26.2|dev=snap5|Added density function {{cd|minecraft:interval_select}}.|Removed density function {{cd|minecraft:weird_scale_sampler}}. Its functionality has been replaced with {{cd|interval_select}}.}}
|{{HistoryLine||26.2|dev=snap1|Density function {{cd|minecraft:clamp}} can now take a density function ID as an input.}}
|{{HistoryLine|||dev=snap5|Added density function {{cd|minecraft:interval_select}}.|Removed density function {{cd|minecraft:weird_scale_sampler}}. Its functionality has been replaced with {{cd|interval_select}}.}}
|{{HistoryLine|java upcoming}}
|{{HistoryLine|java upcoming}}
|{{HistoryLine||26.3|dev=snap4|Added the following density functions:
|{{HistoryLine||26.3|dev=snap4|Added the following density functions:

Latest revision as of 11:04, 2 August 2026

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

Template:TOC

JSON format

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

If the Template:Nbt is constant, a shorthand format is:

  • Template:Nbt: A constant number. Value between −1000000.0 and 1000000.0 (both inclusive).

Marker functions

Template:Cd

Only computes the input density once per horizontal position.

Template:Cd

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

Template:Cd

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

Template:Cd

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.

Template:Cd

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.

Noise sampling functions

These density functions are used to sample noises.

Template:Cd

Samples a noise.

Template:Cd

Samples a legacy noise. Template:Info needed

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, old_blended_noise).
    • Template:Nbt: Value between 0.001 and 1000.0 (both inclusive).
    • Template:Nbt: Value between 0.001 and 1000.0 (both inclusive).
    • Template:Nbt: Value between 0.001 and 1000.0 (both inclusive).
    • Template:Nbt: Value between 0.001 and 1000.0 (both inclusive).
    • Template:Nbt: Value between 1.0 and 8.0 (both inclusive).

Template:Cd

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

Template:Cd

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

Template:Cd

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

Template:Cd

Similar to noise, but first shifts the input coordinates.

Mathematical density functions

These density functions are used to perform mathematical operations.

Template:Cd

Calculates the absolute value of the input density function.

Template:Cd

Adds two density functions together.

Template:Cd

Rounds the input value to positive infinity.Template:Upcoming

Template:Cd

Clamps the input between two values.

Template:Cd

A constant value.

Template:Cd

Cubes the input (x^3).

Template:Cd

Performs division between two arguments.Template:Upcoming

Template:Cd

Rounds the input value to negative infinity.Template:Upcoming

Template:Cd

Renamed to Template:Cd.Template:Upcoming Inverts the input (1/x).

Template:Cd

Computes the natural logarithm of the given input.Template:Upcoming

Template:Cd

Multiplies two inputs.

Template:Cd

Returns the minimum of two inputs.

Template:Cd

Returns the maximum of two inputs.

Template:Cd

Negates the input.Template:Upcoming

Template:Cd

Raises the given base value to an exponent.Template:Upcoming

Template:Cd

Rounds the input value to to the nearest integer (ties round up).Template:Upcoming

Template:Cd

Performs subtraction between two arguments.Template:Upcoming

Template:Cd

Computes the sign of the given input. If positive, it returns as 1. If the input is 0, it returns 0. If negative, it returns as -1.Template:Upcoming

Template:Cd

Computes the square root of the given input.Template:Upcoming

Template:Cd

Squares the input. (x^2)

Template:Cd

Rounds the input value to 0.Template:Upcoming

Mapped density functions

These density functions map a set of values onto another set of values.

Template:Cd

File:Gradient tiling.png
Demonstration of the different tiling options for the Template:Cd density functionTemplate:Upcoming, using both an input range of -100 to 100 and an output range of -1 to 1.

Clamps the given coordinate and maps the gradient to a range.Template:Upcoming

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, gradient).
    • Template:Nbt: Template:Cd, Template:Cd. or Template:Cd: The axis over which to define the gradient .
    • Template:Nbt: How the density function handles values outside the specified coordinate range. 3 options:
      • clamp_to_edge: outside the gradient boundaries, the value at the nearest boundary will be used.
      • repeat: The gradient will be repeated outside its boundaries.
      • mirrored_repeat: The gradient will be repeated as such that odd repetitions are mirrored, ensuring continuity between repetitions.
    • Template:NbtTemplate:Upcoming: The coordinate at which the gradient starts.
    • Template:Nbt: The coordinate at which the gradient ends. It must not equal Template:Cd.
    • Template:Nbt: The value at which the gradient starts.
    • Template:Nbt: The value at which the gradient ends.

Template:Cd

Performs (unclamped) linear interpolation between two arguments based on an alpha.Template:Upcoming The returned value is: first*(1-alpha) + second*alpha

Template:Cd

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

Template:Cd

Computes a cubic spline.

Template:Cd

Replaced with Template:Cd.Template:Upcoming

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

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, y_clamped_gradient).
    • Template:Nbt: The value to be mapped to from_value. Value between −4064 and 4062 (both inclusive).
    • Template:Nbt: The value to be mapped to to_value. Value between −4064 and 4062 (both inclusive).
    • Template:Nbt: The value to map from_y to. Value between −1000000.0 and 1000000.0 (both inclusive).
    • Template:Nbt: The value to map to_y to. Value between −1000000.0 and 1000000.0 (both inclusive).

Conditional density functions

These density functions are used to apply "if-then" logic.

Template:Cd

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

Template:Cd

Selects between a number of density functions based on an input density function and a set of threshold values.

Template:Cd

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

Template:Cd

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

Other density functions

Template:Cd

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.

Template:Cd

Used in vanilla for smooth transition to chunks generated in old versions.Template:Info needed

Template:Cd

Used in vanilla for smooth transition to chunks generated in old versions.Template:Info needed

Template:Cd

Used in vanilla for smooth transition to chunks generated in old versions.Template:Info needed

Template:Cd

File:Distance to point options.png
Demonstration of the different metric options for the Template:Cd density functionTemplate:Upcoming, using the distance from the point (0, 0).

Computes the distance to a fixed point using the specified distance function.Template:Upcoming

Template:Cd

Renamed to Template:Cd.Template:Upcoming 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.

Template:Cd

Scans through a column of an input density and returns the topmost y-level that is above 0. If no such position exists within the bounds, the Template:Nbt is returned.

Template:Cd

Removes a dimension from the input domain by taking a "slice" along an axis with a specific coordinate (e.g. with the axis equaling y and the coordinate of 0, a slice will be taken along the XZ plane, with all values sampled at y=0).Template:Upcoming

Removed density functions

Template:Outdated

Template:Cd

Removed in Minecraft:22w12a

The legacy "spline"

Removed in Minecraft:22w11a

Template:Cd

Removed in Minecraft:22w11a

Calculate the spline from the noise settings.

Template:Cd

Removed in Minecraft:26.2-snap5

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

History

Template:HistoryTable

Issues

Template:Issue list

References

Template:Reflist

External links

Navigation

Template:Navbox Java Edition technical

Minecraft:de:Dichtefunktion Minecraft:fr:Fonction de densité Minecraft:ko:밀도 함수 Minecraft:pt:Função de densidade Minecraft:zh:密度函数