Skip to content

Add support for `interval_select´ density function type and fix #78 - #81

Closed
annhilati wants to merge 2 commits into
misode:mainfrom
annhilati:main
Closed

Add support for `interval_select´ density function type and fix #78#81
annhilati wants to merge 2 commits into
misode:mainfrom
annhilati:main

Conversation

@annhilati

Copy link
Copy Markdown

Description

This PR addresses two issues related to Density Functions to improve parity with Vanilla Minecraft:

  1. Fix mul and add neglecting propagation of non-finite values (Fixes [Density Functions] mul and add with 0 neglect propagation of non-finite values #78)
    When parsing mul or add operations where one of the arguments is a constant (like 0), Deepslate previously unconditionally evaluated this as an Ap2 function, which short-circuited and prevented the evaluation of the second argument. This caused discrepancies with Vanilla Minecraft when evaluating non-finite values like Infinity and NaN.
    To match Vanilla's parsing optimizations, this PR introduces a MulOrAdd transformer class. The parser (fromJson) and mapAll methods have been updated to wrap operations involving a constant into this MulOrAdd class, which correctly evaluates the dynamic input first before applying the constant.

  2. Add support for interval_select (Fixes [Density Functions] Add support for interval_select #80)
    Added the IntervalSelect class mapping to the interval_select DensityFunction, fully porting the Vanilla Java implementation. This includes accurate compute, mapAll, and min/max implementations.

Changes Made

  • Added IntervalSelect class to DensityFunction.ts.
  • Added MulOrAdd transformer class to DensityFunction.ts.
  • Created a createAp2 helper to safely instantiate MulOrAdd or Ap2 based on whether the inputs are constants.
  • Updated DensityFunction.fromJson to parse interval_select and utilize the new createAp2 logic.
  • Added tests for interval_select and the 0 * Infinity propagation edge-case in DensityFunction.test.ts.

Note: AI assistance was used to help port the Java implementation and fix the parsing logic, but all changes have been verified against the existing test suite.

@misode

misode commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Thanks for your work on this. I am going to close this and implement this myself, partly because this really should've been split in two PR's. I might take a look at some of your tests though to figure out #78 issue.

@misode misode closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Density Functions] Add support for interval_select [Density Functions] mul and add with 0 neglect propagation of non-finite values

2 participants