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 1: Line 1:
{{Exclusive|java}}
{{Exclusive|java}}
{{needs update|Add "interval_select" function.}}
'''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 <code>data/<namespace>/worldgen/density_function</code>. They are referenced from the [[Minecraft:noise router]] in [[Minecraft:noise settings]].
'''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 <code>data/<namespace>/worldgen/density_function</code>. They are referenced from the [[Minecraft:noise router]] in [[Minecraft:noise settings]].


Line 21: Line 20:


== Marker functions ==
== Marker functions ==
=== interpolated ===
=== cache_2d ===
Interpolates at each block in one cell based on the input density function value of some cells around. The size of each cell is <code>size_horizontal * 4</code> and <code>size_vertical * 4</code>. Used often in combination with <code>flat_cache</code>.
Only computes the input density once per horizontal position.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>interpolated</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_2d</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input to be interpolated.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input to be cached.
</div>
</div>


=== flat_cache ===
=== cache_all_in_cell ===
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 <code>interpolated</code>.
Used by the game onto <code>final_density</code> and should not be referenced in data packs.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>flat_cache</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_all_in_cell</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input to be cached.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input to be cached.
</div>
</div>


=== cache_2d ===
=== cache_once ===
Only computes the input density once per horizontal position.
If this density function is referenced twice, it is only computed once per block position.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_2d</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_once</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input to be cached.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input to be cached.
</div>
</div>


=== cache_once ===
=== flat_cache ===
If this density function is referenced twice, it is only computed once per block position.
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 <code>interpolated</code>.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_once</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>flat_cache</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input to be cached.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input to be cached.
</div>
</div>


=== cache_all_in_cell ===
=== interpolated ===
Used by the game onto <code>final_density</code> and should not be referenced in data packs.
Interpolates at each block in one cell based on the input density function value of some cells around. The size of each cell is <code>size_horizontal * 4</code> and <code>size_vertical * 4</code>. Used often in combination with <code>flat_cache</code>.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cache_all_in_cell</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>interpolated</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input to be cached.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input to be interpolated.
</div>
</div>


Line 67: Line 66:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>abs</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>abs</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
 
=== square ===
Squares the input. (<code>x^2</code>)
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>square</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>


Line 83: Line 74:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cube</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>cube</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>


Line 91: Line 82:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>half_negative</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>half_negative</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
=== interval_select ===
Selects between a number of density functions based on an input density function and a set of threshold values.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>interval_select</code>).
** {{nbt|int|input}}: The value to be compared with any given {{cd|thresholds}}.
** {{nbt|float|thresholds}}: The threshold values to compare {{cd|input}} with.
*** If the input value is less than the threshold values, the result of {{cd|functions[i]}} will be selected.
*** If the input value is greater than the last threshold value, the last function will be selected.
*** There must be one fewer {{cd|thresholds}} than {{cd|functions}}.
** {{nbt|list|functions}}: The resulting functions (at least two) to be selected from.
*** There must be one more element in {{cd|functions}} than {{cd|thresholds}}.
</div>
=== invert ===
Named {{cd|reciprocal}}.{{upcoming|JE 26.3}}
Inverts the input (<code>1/x</code>).
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>invert</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>
Line 99: Line 113:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>quarter_negative</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>quarter_negative</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>


=== squeeze ===
=== square ===
First clamps the input between −1 and 1, then transforms it using x/2 - x*x*x/24.
Squares the input. (<code>x^2</code>)
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>squeeze</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>square</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>


=== invert ===
=== squeeze ===
Inverts the input (<code>1/x</code>).
First clamps the input between −1 and 1, then transforms it using x/2 - x*x*x/24.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>invert</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>squeeze</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The input of the calculation.
</div>
</div>


Line 124: Line 138:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>add</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>add</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}{{until|JE 26.3}} / {{nbt|double|left}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}: {{json ref/density function}} &mdash; The second input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}{{until|JE 26.3}} / {{nbt|double|right}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The second input of the calculation.
</div>
 
=== div ===
Performs division between two arguments.{{upcoming|JE 26.3}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>div</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|left}} &mdash; The left-hand side of the operation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|right}} &mdash; The right-hand side of the operation.
</div>
</div>


Line 133: Line 156:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>mul</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>mul</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}{{until|JE 26.3}} / {{nbt|double|left}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}: {{json ref/density function}} &mdash; The second input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}{{until|JE 26.3}} / {{nbt|double|right}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The second input of the calculation.
</div>
</div>


Line 142: Line 165:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>min</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>min</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}{{until|JE 26.3}} / {{nbt|double|left}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}: {{json ref/density function}} &mdash; The second input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}{{until|JE 26.3}} / {{nbt|double|right}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The second input of the calculation.
</div>
</div>


Line 151: Line 174:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>max</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>max</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument1}}{{until|JE 26.3}} / {{nbt|double|left}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The first input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}: {{json ref/density function}} &mdash; The second input of the calculation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument2}}{{until|JE 26.3}} / {{nbt|double|right}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The second input of the calculation.
</div>
 
=== sub ===
Performs subtraction between two arguments.{{upcoming|JE 26.3}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>sub</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|left}} &mdash; The left-hand side of the operation.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|right}} &mdash; The right-hand side of the operation.
</div>
</div>


== Other density functions ==
== Other density functions ==
=== beardifier ===
Adds beards for structures (see the <code>terrain_adaptation</code> field in [[Minecraft:Structure/JSON format|structures]]). Its value is added to the <code>final_density</code> in noise setting by the game. Should not be referenced in data packs.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>beardifier</code>).
</div>
=== blend_alpha ===
=== blend_alpha ===
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
Line 163: Line 202:
</div>
</div>


=== blend_offset ===
=== blend_density ===
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>blend_offset</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>blend_density</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}{{until|JE 26.3}} / {{nbt|double|input}}{{upcoming|JE 26.3}}: {{json ref/density function}} &mdash; The desired density of new chunks.
</div>
</div>


=== blend_density ===
=== blend_offset ===
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
Used in vanilla for smooth transition to chunks generated in old versions.{{Info needed}}
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>blend_density</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>blend_offset</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|argument}}: {{json ref/density function}} &mdash; The desired density of new chunks.
</div>
</div>


=== beardifier ===
=== ceil ===
Adds beards for structures (see the <code>terrain_adaptation</code> field in [[Minecraft:Structure/JSON format|structures]]). Its value is added to the <code>final_density</code> in noise setting by the game. Should not be referenced in data packs.
Rounds the input value to positive infinity.{{upcoming|JE 26.3}}
 
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>beardifier</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>ceil</code>).
** {{nbt|int|input}}: The input to round.
** {{nbt|int|multiple}}: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.
</div>
</div>


=== old_blended_noise ===
=== clamp ===
Samples a legacy noise. {{Info needed}}
Clamps the input between two values.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>old_blended_noise</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>clamp</code>).
** {{Nbt|double|xz_scale}}: Value between 0.001 and 1000.0 (both inclusive).
** {{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|y_scale}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|min}}: The lower bound. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|xz_factor}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|max}}: The upper bound. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|y_factor}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|smear_scale_multiplier}}: Value between 1.0 and 8.0 (both inclusive).
</div>
</div>


=== noise ===
=== constant ===
Samples a [[Minecraft:Custom_noise|noise]].
A constant value.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>noise</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>constant</code>).
** {{Nbt|string|noise}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|double|argument}}{{until|JE 26.3}} / {{nbt|double|value}}{{upcoming|JE 26.3}}: A constant value. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|xz_scale}}: Scales the X and Z before sampling.
** {{Nbt|double|y_scale}}: Scales the Y before sampling.
</div>
</div>


Line 214: Line 252:
</div>
</div>


=== shifted_noise ===
=== find_top_surface ===
Similar to <code>noise</code>, but first shifts the input coordinates.
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 {{Nbt|int|lower_bound}} is returned.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>find_top_surface</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|density}}: {{json ref/density function}} &mdash; The density function to scan.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|upper_bound}}: {{json ref/density function}} &mdash; The y-level to start the scan at. Usually a 2D density function.
** {{Nbt|int|lower_bound}}: The y-level to stop the scan.
** {{Nbt|int|cell_height}}: The resolution of the scan. E.g. if set to <code>4</code>, then only every 4th block is checked.
</div>
 
=== floor ===
Rounds the input value to negative infinity.{{upcoming|JE 26.3}}
 
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>floor</code>).
** {{nbt|int|input}}: The input to round.
** {{nbt|int|multiple}}: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.
</div>
 
=== lerp ===
Performs (unclamped) linear interpolation between two arguments based on an alpha.{{upcoming|JE 26.3}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>lerp</code>).
** {{nbt|integer|alpha}}: The interpolation factor (e.g. 0 = first, 1 = second). Any value outside of {{cd|[0; 1]}} will extrapolate.
** {{nbt|integer|first}}: the value at {{cd|<nowiki>alpha=0</nowiki>}}.
** {{nbt|integer|second}}: the value at {{cd|<nowiki>alpha=1</nowiki>}}.
</div>
 
=== negate ===
Negates the input.{{upcoming|JE 26.3}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>negate</code>).
** {{nbt|string|input}}: The function to negate.
</div>
 
=== noise ===
Samples a [[Minecraft:Custom_noise|noise]].
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shifted_noise</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>noise</code>).
** {{Nbt|string|noise}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|string|noise}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|double|xz_scale}}: Scales the X and Z before sampling.
** {{Nbt|double|xz_scale}}: Scales the X and Z before sampling.
** {{Nbt|double|y_scale}}: Scales the Y before sampling.
** {{Nbt|double|y_scale}}: Scales the Y before sampling.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_x}}: {{json ref/density function}} &mdash; offset of the position in the X direction.
</div>
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_y}}: {{json ref/density function}} &mdash; offset of the position in the Y direction.
 
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_z}}: {{json ref/density function}} &mdash; offset of the position in the Z direction.
=== old_blended_noise ===
Samples a legacy noise. {{Info needed}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>old_blended_noise</code>).
** {{Nbt|double|xz_scale}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|y_scale}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|xz_factor}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|y_factor}}: Value between 0.001 and 1000.0 (both inclusive).
** {{Nbt|double|smear_scale_multiplier}}: Value between 1.0 and 8.0 (both inclusive).
</div>
</div>


Line 237: Line 323:
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|when_in_range}}:  {{json ref/density function}} &mdash; Used when the input is inside the range.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|when_in_range}}:  {{json ref/density function}} &mdash; Used when the input is inside the range.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|when_out_of_range}}:  {{json ref/density function}} &mdash; Used when the input is outside the range.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|when_out_of_range}}:  {{json ref/density function}} &mdash; Used when the input is outside the range.
</div>
=== round ===
Rounds the input value to to the nearest integer (ties round up).{{upcoming|JE 26.3}}
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>round</code>).
** {{nbt|int|input}}: The input to round.
** {{nbt|int|multiple}}: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.
</div>
=== shift ===
Samples a noise at <code>(x/4, y/4, z/4)</code>, then multiplies it by 4.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift</code>).
** {{Nbt|string|argument}}{{until|JE 26.3}} / {{nbt|string|noise}}{{upcoming|JE 26.3}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
</div>
</div>


Line 244: Line 348:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift_a</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift_a</code>).
** {{Nbt|string|argument}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|string|argument}}{{until|JE 26.3}} / {{nbt|string|noise}}{{upcoming|JE 26.3}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
</div>
</div>


Line 252: Line 356:
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift_b</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift_b</code>).
** {{Nbt|string|argument}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|string|argument}}{{until|JE 26.3}} / {{nbt|string|noise}}{{upcoming|JE 26.3}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
</div>
</div>


=== shift ===
=== shifted_noise ===
Samples a noise at <code>(x/4, y/4, z/4)</code>, then multiplies it by 4.
Similar to <code>noise</code>, but first shifts the input coordinates.
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shift</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>shifted_noise</code>).
** {{Nbt|string|argument}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
** {{Nbt|string|noise}}: {{json ref|noise|Custom noise}} &mdash; The noise to sample.
</div>
** {{Nbt|double|xz_scale}}: Scales the X and Z before sampling.
 
** {{Nbt|double|y_scale}}: Scales the Y before sampling.
=== clamp ===
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_x}}: {{json ref/density function}} &mdash; offset of the position in the X direction.
Clamps the input between two values.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_y}}: {{json ref/density function}} &mdash; offset of the position in the Y direction.
<div class="treeview">
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_z}}: {{json ref/density function}} &mdash; offset of the position in the Z direction.
* {{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>
</div>


Line 287: Line 386:
</div>
</div>


=== constant ===
=== truncate ===
A constant value.
Rounds the input value to 0.{{upcoming|JE 26.3}}
 
<div class="treeview">
<div class="treeview">
* {{nbt|compound}}: Root object.
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>constant</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>truncate</code>).
** {{Nbt|double|argument}}: A constant value. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{nbt|int|input}}: The input to round.
** {{nbt|int|multiple}}: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.
</div>
</div>


Line 304: Line 405:
** {{Nbt|double|from_value}}: The value to map <code>from_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|from_value}}: The value to map <code>from_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|to_value}}: The value to map <code>to_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
** {{Nbt|double|to_value}}: The value to map <code>to_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
</div>
=== find_top_surface ===
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 {{Nbt|int|lower_bound}} is returned.
<div class="treeview">
* {{nbt|compound}}: Root object.
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>find_top_surface</code>).
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|density}}: {{json ref/density function}} &mdash; The density function to scan.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|upper_bound}}: {{json ref/density function}} &mdash; The y-level to start the scan at. Usually a 2D density function.
** {{Nbt|int|lower_bound}}: The y-level to stop the scan.
** {{Nbt|int|cell_height}}: The resolution of the scan. E.g. if set to <code>4</code>, then only every 4th block is checked.
</div>
</div>


Line 400: Line 490:
|{{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=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||26.3|dev=snap4|Added the following density functions:
* {{cd|ceil}}
* {{cd|div}}
* {{cd|floor}}
* {{cd|negate}}
* {{cd|lerp}}
* {{cd|round}}
* {{cd|sub}}
* {{cd|truncate}}
|{{cd|invert}} has been renamed to {{cd|reciprocal}}.
|Numerous {{cd|argument}} fields in density functions have been renamed.}}
}}
}}



Latest revision as of 11:06, 17 July 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

cache_2d

Only computes the input density once per horizontal position.

cache_all_in_cell

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

cache_once

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

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.

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.

Mapped density functions

abs

Calculates the absolute value of the input density function.

cube

Cubes the input (x^3).

half_negative

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

interval_select

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

invert

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

quarter_negative

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

square

Squares the input. (x^2)

squeeze

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

Functions with two arguments

add

Adds two density functions together.

div

Performs division between two arguments.Template:Upcoming

mul

Multiplies two inputs.

min

Returns the minimum of two inputs.

max

Returns the maximum of two inputs.

sub

Performs subtraction between two arguments.Template:Upcoming

Other density functions

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.

blend_alpha

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

blend_density

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

blend_offset

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

ceil

Rounds the input value to positive infinity.Template:Upcoming

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, ceil).
    • Template:Nbt: The input to round.
    • Template:Nbt: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.

clamp

Clamps the input between two values.

constant

A constant value.

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.

find_top_surface

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.

floor

Rounds the input value to negative infinity.Template:Upcoming

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, floor).
    • Template:Nbt: The input to round.
    • Template:Nbt: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.

lerp

Performs (unclamped) linear interpolation between two arguments based on an alpha.Template:Upcoming

negate

Negates the input.Template:Upcoming

noise

Samples a noise.

old_blended_noise

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).

range_choice

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

round

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

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, round).
    • Template:Nbt: The input to round.
    • Template:Nbt: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.

shift

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

shift_a

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

shift_b

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

shifted_noise

Similar to noise, but first shifts the input coordinates.

spline

Computes a cubic spline.

truncate

Rounds the input value to 0.Template:Upcoming

  • Template:Nbt: Root object.
    • Template:Nbt: The ID of the density function type (in this case, truncate).
    • Template:Nbt: The input to round.
    • Template:Nbt: The output will be rounded to an integer multiple of this value. If not specified, it defaults to a constant 1.

y_clamped_gradient

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

  • 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).

Removed density functions

Template:Outdated

slide

Removed in Minecraft:22w12a

The legacy "spline"

Removed in Minecraft:22w11a

terrain_shaper_spline

Removed in Minecraft:22w11a

Calculate the spline from the noise settings.

weird_scaled_sampler

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:密度函数