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 100: Line 100:


=== invert ===
=== invert ===
Named {{cd|reciprocal}}.{{upcoming|JE 26.3}}
Renamed to {{cd|reciprocal}}.{{upcoming|JE 26.3}}
Inverts the input (<code>1/x</code>).
Inverts the input (<code>1/x</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>invert</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>invert</code>{{until|JE 26.3}} / <code>reciprocal</code>{{upcoming|JE 26.3}}).
** {{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 243: Line 243:
** {{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>constant</code>).
** {{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|argument}}{{until|JE 26.3}} / {{nbt|double|value}}{{upcoming|JE 26.3}}: A constant value. Value between −1000000.0 and 1000000.0 (both inclusive).
</div>
=== distance_to_point ===
Computes the distance to a fixed point using the specified distance function.{{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>distance_to_point</code>).
** {{nbt|int-array|point}}: {{cd|[x, y, z]}}; the point to compute distance to
** {{nbt|string|metric}}:
*** {{nbt|string|euclidean}}: (i.e. {{cd|sqrt(dx^2 + dy^2 + dz^2)}})
*** {{nbt|string|euclidean_squared}}: (i.e. {{cd|dx^2 + dy^2 + dz^2}})
*** {{nbt|string|manhattan}}: (i.e. {{cd|abs(dx) + abs(dy) + abs(dz)}})
*** {{nbt|string|chebyshev}}: (i.e. {{cd|max(abs(dx), abs(dy), abs(dz))}})
</div>
</div>


=== end_islands ===
=== end_islands ===
Renamed to {{cd|end_outer_islands}}.{{upcoming|JE 26.3}}
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.
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.
<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>end_islands</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>end_islands</code>{{until|JE 26.3}} / <code>end_outer_islands</code>{{upcoming|JE 26.3}}).
</div>
</div>


Line 271: Line 286:
** {{nbt|int|input}}: The input to round.
** {{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.
** {{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>
=== log ===
Computes the natural logarithm of the given 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>log</code>).
** {{nbt|int|input}}: the value for which to compute the natural logarithm.
</div>
</div>


Line 311: Line 335:
** {{Nbt|double|y_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).
** {{Nbt|double|smear_scale_multiplier}}: Value between 1.0 and 8.0 (both inclusive).
</div>
=== pow ===
Raises the given base value to an exponent.{{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>pow</code>).
** {{nbt|int|base}}: the base value.
** {{nbt|int|exponent}}: the exponent.
</div>
</div>


Line 370: Line 404:
** {{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_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.
** {{Nbt|string}}{{Nbt|double}}{{Nbt|compound|shift_z}}: {{json ref/density function}} &mdash; offset of the position in the Z direction.
</div>
=== sign ===
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.{{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>sign</code>).
** {{nbt|int|input}}: the value for which to compute the sign.
</div>
=== slice ===
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).{{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>slice</code>).
** {{nbt|int|axis}}: {{cd|x}}, {{cd|y}}, or {{cd|z}}; the axis to remove.
** {{nbt|int|coordinate}}: The fixed coordinate to be passed to the input function.
** {{nbt|int|input}}: The input function.
</div>
</div>


Line 384: Line 438:
***** {{Nbt|float}}{{Nbt|compound|value}}: The value of this point. Can be either a number or a spline object.
***** {{Nbt|float}}{{Nbt|compound|value}}: The value of this point. Can be either a number or a spline object.
***** {{Nbt|float|derivative}}: The slope at this point.
***** {{Nbt|float|derivative}}: The slope at this point.
</div>
=== sqrt ===
Computes the square root of the given 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>sqrt</code>).
** {{nbt|int|input}}: the value for which to compute the square root.
</div>
</div>


Line 397: Line 460:


=== y_clamped_gradient ===
=== y_clamped_gradient ===
Clamps the Y coordinate between <code>from_y</code> and <code>to_y</code> and then linearly maps it to a range.
Renamed to {{cd|gradient}}.{{upcoming|JE 26.3}}
Clamps the Y coordinate between <code>from_y</code> and <code>to_y</code> and then linearly maps it to a range.{{until|JE 26.3}} / Clamps the given coordinate and maps the gradient to a range.{{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>y_clamped_gradient</code>).
** {{Nbt|string|type}}: The ID of the density function type (in this case, <code>y_clamped_gradient</code>{{until|JE 26.3}} / <code>gradient</code>{{upcoming|JE 26.3}}).
** {{Nbt|int|from_y}}: The value to be mapped to <code>from_value</code>. Value between −4064 and 4062 (both inclusive).
** {{nbt|short|axis}}{{upcoming|JE 26.3}}: {{cd|x}}, {{cd|y}}. or {{cd|z}}: The axis over which to define the gradient .
** {{Nbt|int|to_y}}: The value to be mapped to <code>to_value</code>. Value between −4064 and 4062 (both inclusive).
** {{nbt|string|tilling}}{{upcoming|JE 26.3}}:
** {{Nbt|double|from_value}}: The value to map <code>from_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
*** {{nbt|int|clamp_to_edge}}: outside the gradient boundaries, the value at the nearest boundary will be used.
** {{Nbt|double|to_value}}: The value to map <code>to_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).
*** {{nbt|string|repeat}}: The gradient will be repeated outside its boundaries.
*** {{nbt|string|mirrored_repeat}}: The gradient will be repeated as such that odd repetitions are mirrored, ensuring continuity between repetitions.
** {{Nbt|int|from_y}}{{until|JE 26.3}} / {{nbt|int|from_coordinate}}{{upcoming|JE 26.3}}: The value to be mapped to <code>from_value</code>. Value between −4064 and 4062 (both inclusive).{{until|JE 26.3}} The coordinate at which the gradient starts.{{upcoming|JE 26.3}}
** {{Nbt|int|to_y}}{{until|JE 26.3}} / {{nbt|int|to_coordinate}}{{upcoming|JE 26.3}}: The value to be mapped to <code>to_value</code>. Value between −4064 and 4062 (both inclusive).{{until|JE 26.3}} The coordinate at which the gradient ends. It must not equal {{cd|from_coordinate}}.{{upcoming|JE 26.3}}
** {{Nbt|double|from_value}}{{until|JE 26.3}} / {{nbt|float|from_value}}{{upcoming|JE 26.3}}: The value to map <code>from_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).{{until|JE 26.3}} / The value at which the gradient starts.{{upcoming|JE 26.3}}
** {{Nbt|double|to_value}}{{until|JE 26.3}} / {{nbt|float|to_value}}{{upcoming|JE 26.3}}: The value to map <code>to_y</code> to. Value between −1000000.0 and 1000000.0 (both inclusive).{{until|JE 26.3}} / The value at which the gradient ends.{{upcoming|JE 26.3}}
</div>
</div>


Line 502: Line 571:
|{{cd|invert}} has been renamed to {{cd|reciprocal}}.
|{{cd|invert}} has been renamed to {{cd|reciprocal}}.
|Numerous {{cd|argument}} fields in density functions have been renamed.}}
|Numerous {{cd|argument}} fields in density functions have been renamed.}}
|{{HistoryLine|||dev=snap6|Added the following density functions:
* {{cd|distance_to_point}}
* {{cd|log}}
* {{cd|pow}}
* {{cd|sign}}
* {{cd|slice}}
* {{cd|sqrt}}
|Renamed the following density functions:
* {{cd|end_islands}} to {{cd|end_outer_islands}}
* {{cd|y_clamped_gradient}} to {{cd|gradient}}
}}
}}
}}



Revision as of 11:09, 29 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

Renamed to 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.

distance_to_point

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

end_islands

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.

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.

log

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

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

pow

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

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.

sign

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

slice

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

spline

Computes a cubic spline.

sqrt

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

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

Renamed to Template:Cd.Template:Upcoming Clamps the Y coordinate between from_y and to_y and then linearly maps it to a range.Template:Until / Clamps the given coordinate and maps the gradient to a range.Template:Upcoming

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