From 6b80229269e05c52b295059680b3725f29b95cdb Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 8 Oct 2026 01:38:28 +0200 Subject: [PATCH] Decode clamped_normal integer providers Mth.normal sampling with float clamping and a saturating int cast, as used by the pointed dripstone and sulfur spike placement offsets. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../src/worldgen/value_provider.rs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/horizon-world/src/worldgen/value_provider.rs b/crates/horizon-world/src/worldgen/value_provider.rs index bee692502..ba081e3e9 100644 --- a/crates/horizon-world/src/worldgen/value_provider.rs +++ b/crates/horizon-world/src/worldgen/value_provider.rs @@ -123,6 +123,12 @@ pub enum IntProvider { min: i32, max: i32, }, + ClampedNormal { + mean: f32, + deviation: f32, + min: i32, + max: i32, + }, } impl IntProvider { pub fn from_json(json: &str) -> Result { @@ -170,6 +176,12 @@ impl IntProvider { } Ok(Self::Trapezoid { min, max, plateau }) } + "minecraft:clamped_normal" => Ok(Self::ClampedNormal { + mean: required(&object, "mean").and_then(float)?, + deviation: required(&object, "deviation").and_then(float)?, + min, + max, + }), "minecraft:clamped" => Ok(Self::Clamped { source: Box::new(Self::decode( required(&object, "source")?, @@ -196,7 +208,8 @@ impl IntProvider { Self::Uniform { min, max } | Self::BiasedToBottom { min, max } | Self::VeryBiasedToBottom { min, max } - | Self::Trapezoid { min, max, .. } => [*min, *max], + | Self::Trapezoid { min, max, .. } + | Self::ClampedNormal { min, max, .. } => [*min, *max], Self::Clamped { source, min, max } => { let bounds = source.bounds(); [(*min).max(bounds[0]), (*max).min(bounds[1])] @@ -236,6 +249,17 @@ impl IntProvider { let value = source.sample(random)?; Ok(if value < *min { *min } else { value.min(*max) }) } + // Mth.normal, then float Mth.clamp and a saturating int cast. + Self::ClampedNormal { + mean, + deviation, + min, + max, + } => { + let value = mean + random.next_gaussian() as f32 * deviation; + let (min, max) = (*min as f32, *max as f32); + Ok((if value < min { min } else { value.min(max) }) as i32) + } } } }