Interface DensityFunction

All Superinterfaces:
Keyed, Wrapper
All Known Subinterfaces:
BlendAlpha, BlendOffset, ClampedTransformer, ConstantSimpleFunction, EndIslands, FindTopSurface, MappedNoiseFunction, MappedTransformer, Marker, NoiseFunction, NoiseParameterFunction, PureTransformer, RangeChoice, ReferencedDensityFunction, ShiftedFunction, ShiftedNoise2dFunction, SimpleFunction, TwoArgumentSimpleFunction, YClampedGradient, ZeroSimpleFunction

@NullMarked @AsOf("2.4.0") public interface DensityFunction extends Wrapper, Keyed
A density function. Either a reference to a registered one or an authored composition of other density functions.
Since:
2.4.0
See Also:
  • Method Details

    • resourceKey

      @AsOf("3.0.0") Optional<ResourceKey> resourceKey()
      The resource key of the density function, if present.
      Returns:
      the resource key of the density function, if present
      Since:
      3.0.0
    • add

      @AsOf("3.0.0") default TwoArgumentSimpleFunction add(DensityFunction other)
      Adds this density function to another density function.
      Parameters:
      other - the density function to add to this one
      Returns:
      a density function that is the sum of the two inputs
      Since:
      3.0.0
    • mul

      @AsOf("3.0.0") default TwoArgumentSimpleFunction mul(DensityFunction other)
      Multiplies this density function by another density function.
      Parameters:
      other - the density function to multiply this one by
      Returns:
      a density function that is the product of the two inputs
      Since:
      3.0.0
    • min

      @AsOf("3.0.0") default TwoArgumentSimpleFunction min(DensityFunction other)
      Returns the minimum of this density function and another density function.
      Parameters:
      other - the density function to compare with
      Returns:
      a density function that is the minimum of the two inputs
      Since:
      3.0.0
    • max

      @AsOf("3.0.0") default TwoArgumentSimpleFunction max(DensityFunction other)
      Returns the maximum of this density function and another density function.
      Parameters:
      other - the density function to compare with
      Returns:
      a density function that is the maximum of the two inputs
      Since:
      3.0.0
    • abs

      @AsOf("3.0.0") default MappedTransformer abs()
      Calculates the absolute value of this density function.
      Returns:
      a density function producing |x|
      Since:
      3.0.0
    • square

      @AsOf("3.0.0") default MappedTransformer square()
      Squares this density function.
      Returns:
      a density function producing x * x
      Since:
      3.0.0
    • cube

      @AsOf("3.0.0") default MappedTransformer cube()
      Cubes this density function.
      Returns:
      a density function producing x * x * x
      Since:
      3.0.0
    • halfNegative

      @AsOf("3.0.0") default MappedTransformer halfNegative()
      Halves this density function where it is negative, leaving it unchanged where positive.
      Returns:
      a density function producing x < 0 ? x / 2 : x
      Since:
      3.0.0
    • quarterNegative

      @AsOf("3.0.0") default MappedTransformer quarterNegative()
      Quarters this density function where it is negative, leaving it unchanged where positive.
      Returns:
      a density function producing x < 0 ? x / 4 : x
      Since:
      3.0.0
    • invert

      @AsOf("3.0.0") default MappedTransformer invert()
      Inverts this density function.
      Returns:
      a density function producing 1 / x
      Since:
      3.0.0
    • squeeze

      @AsOf("3.0.0") default MappedTransformer squeeze()
      Clamps this density function between -1 and 1, then transforms it using x / 2 - x * x * x / 24.
      Returns:
      a density function producing the squeezed value
      Since:
      3.0.0
    • clamp

      @AsOf("3.0.0") default ClampedTransformer clamp(double min, double max)
      Clamps this density function between two values.
      Parameters:
      min - the lower bound
      max - the upper bound
      Returns:
      a density function clamped to [min, max]
      Since:
      3.0.0
    • interpolated

      @AsOf("3.0.0") default Marker interpolated()
      Interpolates this density function at each block in a cell based on the values of surrounding cells. Often used in combination with flatCache().
      Returns:
      an interpolating marker over this density function
      Since:
      3.0.0
    • flatCache

      @AsOf("3.0.0") default Marker flatCache()
      Caches this density function per 4×4 column, computing it only once per column at Y=0. Often used in combination with interpolated().
      Returns:
      a flat-cache marker over this density function
      Since:
      3.0.0
    • cache2d

      @AsOf("3.0.0") default Marker cache2d()
      Computes this density function only once per horizontal position.
      Returns:
      a 2D-cache marker over this density function
      Since:
      3.0.0
    • cacheOnce

      @AsOf("3.0.0") default Marker cacheOnce()
      Computes this density function only once per block position, even when it is referenced twice.
      Returns:
      a cache-once marker over this density function
      Since:
      3.0.0
    • cacheAllInCell

      @AsOf("3.0.0") default Marker cacheAllInCell()
      Caches this density function across a whole cell. Used by the game and should not be referenced in data packs.
      Returns:
      a cache-all-in-cell marker over this density function
      Since:
      3.0.0
    • blendDensity

      @AsOf("3.0.0") default Marker blendDensity()
      Wraps this density function for smooth blending with chunks generated in old versions.
      Returns:
      a blend-density marker over this density function
      Since:
      3.0.0
    • rangeChoice

      @AsOf("3.0.0") default RangeChoice rangeChoice(double minInclusive, double maxExclusive, DensityFunction whenInRange, DensityFunction whenOutOfRange)
      Uses this density function as the value to compare, returning whenInRange when it falls within [minInclusive, maxExclusive) and whenOutOfRange otherwise. Essentially an if-then-else statement.
      Parameters:
      minInclusive - the lower bound of the range, inclusive
      maxExclusive - the upper bound of the range, exclusive
      whenInRange - the density function used when this value is inside the range
      whenOutOfRange - the density function used when this value is outside the range
      Returns:
      a range choice density function
      Since:
      3.0.0
    • findTopSurface

      @AsOf("3.0.0") default FindTopSurface findTopSurface(DensityFunction upperBound, int lowerBound, int cellHeight)
      Scans a column of this density function and returns the topmost Y-level whose value is above 0, or lowerBound if no such position exists within the bounds.
      Parameters:
      upperBound - the Y-level to start the scan at, usually a 2D density function
      lowerBound - the Y-level to stop the scan at, and the value returned when no surface is found
      cellHeight - the resolution of the scan; e.g. 4 checks only every 4th block
      Returns:
      a find top surface density function over this density function
      Since:
      3.0.0
    • constant

      @AsOf("3.0.0") static ConstantSimpleFunction constant(double value)
      Creates a constant density function that always returns the given value.
      Parameters:
      value - the value to return
      Returns:
      a constant density function
      Since:
      3.0.0
    • noise

      @AsOf("3.0.0") static NoiseFunction noise(NoiseParameters noiseParameters, double xzScale, double yScale)
      Samples a noise.
      Parameters:
      noiseParameters - the noise to sample
      xzScale - scales the X and Z before sampling
      yScale - scales the Y before sampling
      Returns:
      a noise density function
      Since:
      3.0.0
    • noise

      @AsOf("3.0.0") static NoiseFunction.Builder noise()
      Creates a new builder for a NoiseFunction.
      Returns:
      a new noise function builder
      Since:
      3.0.0
    • mappedNoise

      @AsOf("3.0.0") static MappedNoiseFunction mappedNoise(NoiseParameters noiseParameters, double xzScale, double yScale, double minTarget, double maxTarget)
      Samples a noise and linearly maps its output to the range [minTarget, maxTarget].
      Parameters:
      noiseParameters - the noise to sample
      xzScale - scales the X and Z before sampling
      yScale - scales the Y before sampling
      minTarget - the minimum value of the output
      maxTarget - the maximum value of the output
      Returns:
      a mapped noise density function
      Since:
      3.0.0
    • mappedNoise

      @AsOf("3.0.0") static MappedNoiseFunction.Builder mappedNoise()
      Creates a new builder for a MappedNoiseFunction.
      Returns:
      a new mapped noise function builder
      Since:
      3.0.0
    • shift

      @AsOf("3.0.0") static ShiftedFunction shift(NoiseParameters noiseParameters)
      Samples a noise at (x/4, y/4, z/4), then multiplies it by 4.
      Parameters:
      noiseParameters - the noise to sample
      Returns:
      a shift density function
      Since:
      3.0.0
    • shiftA

      @AsOf("3.0.0") static ShiftedFunction shiftA(NoiseParameters noiseParameters)
      Samples a noise at (x/4, 0, z/4), then multiplies it by 4.
      Parameters:
      noiseParameters - the noise to sample
      Returns:
      a shift_a density function
      Since:
      3.0.0
    • shiftB

      @AsOf("3.0.0") static ShiftedFunction shiftB(NoiseParameters noiseParameters)
      Samples a noise at (z/4, x/4, 0), then multiplies it by 4.
      Parameters:
      noiseParameters - the noise to sample
      Returns:
      a shift_b density function
      Since:
      3.0.0
    • shiftedNoise2d

      @AsOf("3.0.0") static ShiftedNoise2dFunction shiftedNoise2d(DensityFunction shiftX, DensityFunction shiftZ, double xzScale, NoiseParameters noiseParameters)
      Samples a noise like noise(NoiseParameters, double, double), but first shifts the input coordinates on the X and Z axes.
      Parameters:
      shiftX - offsets the position in the X direction
      shiftZ - offsets the position in the Z direction
      xzScale - scales the X and Z before sampling
      noiseParameters - the noise to sample
      Returns:
      a shifted noise density function
      Since:
      3.0.0
    • shiftedNoise2d

      @AsOf("3.0.0") static ShiftedNoise2dFunction.Builder shiftedNoise2d()
      Creates a new builder for a ShiftedNoise2dFunction.
      Returns:
      a new shifted noise function builder
      Since:
      3.0.0
    • rangeChoice

      @AsOf("3.0.0") static RangeChoice rangeChoice(DensityFunction input, double minInclusive, double maxExclusive, DensityFunction whenInRange, DensityFunction whenOutOfRange)
      Computes input and returns whenInRange when it falls within [minInclusive, maxExclusive) and whenOutOfRange otherwise. Essentially an if-then-else statement.
      Parameters:
      input - the value to compare against the range
      minInclusive - the lower bound of the range, inclusive
      maxExclusive - the upper bound of the range, exclusive
      whenInRange - the density function used when the input is inside the range
      whenOutOfRange - the density function used when the input is outside the range
      Returns:
      a range choice density function
      Since:
      3.0.0
    • rangeChoice

      @AsOf("3.0.0") static RangeChoice.Builder rangeChoice()
      Creates a new builder for a RangeChoice.
      Returns:
      a new range choice builder
      Since:
      3.0.0
    • yClampedGradient

      @AsOf("3.0.0") static YClampedGradient yClampedGradient(int fromY, int toY, double fromValue, double toValue)
      Clamps the Y coordinate between fromY and toY and then linearly maps it to the range [fromValue, toValue].
      Parameters:
      fromY - the Y coordinate mapped to fromValue
      toY - the Y coordinate mapped to toValue
      fromValue - the value that fromY maps to
      toValue - the value that toY maps to
      Returns:
      a y clamped gradient density function
      Since:
      3.0.0
    • yClampedGradient

      @AsOf("3.0.0") static YClampedGradient.Builder yClampedGradient()
      Creates a new builder for a YClampedGradient.
      Returns:
      a new y clamped gradient builder
      Since:
      3.0.0
    • endIslands

      @AsOf("3.0.0") static EndIslands endIslands(long seed)
      Samples at the current position using the noise algorithm used for end islands. Its minimum value is -0.84375 and its maximum value is 0.5625.
      Parameters:
      seed - the seed used to generate the end islands noise
      Returns:
      an end islands density function
      Since:
      3.0.0
    • blendAlpha

      @AsOf("3.0.0") static BlendAlpha blendAlpha()
      The blend alpha density function, used in vanilla for smooth transitions to chunks generated in old versions.
      Returns:
      the blend alpha density function
      Since:
      3.0.0
    • blendOffset

      @AsOf("3.0.0") static BlendOffset blendOffset()
      The blend offset density function, used in vanilla for smooth transitions to chunks generated in old versions.
      Returns:
      the blend offset density function
      Since:
      3.0.0
    • zero

      @AsOf("3.0.0") static ZeroSimpleFunction zero()
      The density function that always returns zero.
      Returns:
      the zero density function
      Since:
      3.0.0
    • findTopSurface

      @AsOf("3.0.0") static FindTopSurface findTopSurface(DensityFunction density, DensityFunction upperBound, int lowerBound, int cellHeight)
      Scans a column of density and returns the topmost Y-level whose value is above 0, or lowerBound if no such position exists within the bounds.
      Parameters:
      density - the density function to scan
      upperBound - the Y-level to start the scan at, usually a 2D density function
      lowerBound - the Y-level to stop the scan at, and the value returned when no surface is found
      cellHeight - the resolution of the scan; e.g. 4 checks only every 4th block
      Returns:
      a find top surface density function
      Since:
      3.0.0
    • findTopSurface

      @AsOf("3.0.0") static FindTopSurface.Builder findTopSurface()
      Creates a new builder for a FindTopSurface.
      Returns:
      a new find top surface builder
      Since:
      3.0.0
    • reference

      @AsOf("3.0.0") static ReferencedDensityFunction reference(ResourceKey key)
      Creates a reference to a density function already registered under the given key.
      Parameters:
      key - the key of an entry in the density function registry
      Returns:
      a reference to that density function
      Since:
      3.0.0
    • wrap

      @AsOf("3.3.0") @Experimental default DensityFunction wrap()
      Resolves this object's key in Minecraft's density-function registry and decodes the registered value.
      Returns:
      the decoded density function
      Throws:
      IllegalStateException - if this object has no resource key
      Since:
      3.3.0
    • decode

      @AsOf("3.3.0") static DensityFunction decode(Object minecraftDensityFunction)
      Converts a Minecraft density function into a Wyck density function.
      Parameters:
      minecraftDensityFunction - the Minecraft density function to convert
      Returns:
      the Wyck density function
      Since:
      3.3.0