From 796dc320d9b3ccef8c2bc949bbb0db0072ecc05d Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:36:45 +0100 Subject: [PATCH] Use the height adjusted biome temperature for the rain and snow line on the client --- crates/horizon-client/src/biome.rs | 26 ++++++++++++++++++- crates/horizon-client/src/game.rs | 16 ++++-------- crates/horizon-client/src/game/render_tick.rs | 11 +------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/crates/horizon-client/src/biome.rs b/crates/horizon-client/src/biome.rs index c8c15e44e..7aa95e623 100644 --- a/crates/horizon-client/src/biome.rs +++ b/crates/horizon-client/src/biome.rs @@ -1,7 +1,8 @@ //! Biome colours from the pinned biome definitions and colormaps //! (`Biome.getGrassColor`/`getFoliageColor`/..., `BlockTintSources`). use crate::Result; -use horizon_core::{noise::SimplexNoise, random::LegacyRandom}; +use horizon_core::{noise::SimplexNoise, position::BlockPos, random::LegacyRandom}; +use horizon_world::worldgen::biome_temperature::{BiomeTemperatureSettings, TemperatureModifier}; use serde_json::Value; use std::{collections::HashMap, fs, path::Path}; @@ -33,6 +34,8 @@ pub struct BiomeInfo { pub increased_fire_burnout: bool, pub name: String, pub temperature: f32, + /// `climateSettings.temperatureModifier` (frozen oceans). + pub temperature_modifier: TemperatureModifier, pub downfall: f32, pub precipitation: bool, pub grass: u32, @@ -45,6 +48,22 @@ pub struct BiomeInfo { pub fog: Option, pub water_fog: u32, } +impl BiomeInfo { + /// `Biome.getPrecipitationAt` in the Overworld (sea level 63): None + /// without precipitation, else whether it falls as snow + /// (`getHeightAdjustedTemperature` below 0.15). + pub fn snows_at(&self, x: i32, y: i32, z: i32) -> Option { + let settings = BiomeTemperatureSettings { + base_temperature: self.temperature, + modifier: self.temperature_modifier, + has_precipitation: self.precipitation, + downfall: self.downfall, + }; + settings + .has_precipitation + .then(|| settings.height_adjusted(BlockPos::new(x, y, z), 63) < 0.15) + } +} pub struct Biomes { pub list: Vec, pub index: HashMap, @@ -105,6 +124,10 @@ impl Biomes { let attributes = &v["attributes"]; let temperature = v["temperature"].as_f64().unwrap_or(0.5) as f32; let downfall = v["downfall"].as_f64().unwrap_or(0.5) as f32; + let temperature_modifier = match v["temperature_modifier"].as_str() { + Some("frozen") => TemperatureModifier::Frozen, + _ => TemperatureModifier::None, + }; let modifier = match effects["grass_color_modifier"].as_str() { Some("dark_forest") => GrassModifier::DarkForest, Some("swamp") => GrassModifier::Swamp, @@ -135,6 +158,7 @@ impl Biomes { .as_bool() .unwrap_or(false), temperature, + temperature_modifier, downfall, precipitation: v["has_precipitation"].as_bool().unwrap_or(true), grass: color(&effects["grass_color"]) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 58b89a140..e5667f6de 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9670,19 +9670,13 @@ impl Game<'_> { } } /// Whether precipitation at a column is snow (Biome.coldEnoughToSnow: - /// base temperature lowered above y 80) or none (no precipitation). + /// height adjusted temperature) or none (no precipitation). fn precipitation(&self, x: i32, y: i32, z: i32) -> Option { let chunk = self.world.chunks.get(&(x >> 4, z >> 4))?; - let b = self.res.biomes().get(chunk.biome(x, y, z)); - if !b.precipitation { - return None; - } - let t = if y > 80 { - b.temperature - (y - 80) as f32 * 0.05 / 40.0 - } else { - b.temperature - }; - Some(t < 0.15) + self.res + .biomes() + .get(chunk.biome(x, y, z)) + .snows_at(x, y, z) } /// `getHeight(Heightmap.Types.MOTION_BLOCKING, x, z)`: one above the /// highest block in `blocks_motion_in_heightmap` or holding a fluid. diff --git a/crates/horizon-client/src/game/render_tick.rs b/crates/horizon-client/src/game/render_tick.rs index e013c8d29..f5efa392b 100644 --- a/crates/horizon-client/src/game/render_tick.rs +++ b/crates/horizon-client/src/game/render_tick.rs @@ -33,16 +33,7 @@ fn rains_at(world: &World, biomes: &Biomes, x: i32, y: i32, z: i32) -> bool { let Some(chunk) = world.chunks.get(&(x >> 4, z >> 4)) else { return false; }; - let b = biomes.get(chunk.biome(x, y, z)); - if !b.precipitation { - return false; - } - let t = if y > 80 { - b.temperature - (y - 80) as f32 * 0.05 / 40.0 - } else { - b.temperature - }; - t >= 0.15 + biomes.get(chunk.biome(x, y, z)).snows_at(x, y, z) == Some(false) } impl Game<'_> {