Use the height adjusted biome temperature for the rain and snow line on the client
This commit is contained in:
@@ -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<u32>,
|
||||
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<bool> {
|
||||
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<BiomeInfo>,
|
||||
pub index: HashMap<String, u16>,
|
||||
@@ -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"])
|
||||
|
||||
@@ -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<bool> {
|
||||
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.
|
||||
|
||||
@@ -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<'_> {
|
||||
|
||||
Reference in New Issue
Block a user