minedmap/tile_renderer: add biome_at() helper

Retrieve the biome at a given coordinate, possibly offset by a number of
blocks.
This commit is contained in:
Matthias Schiffer 2023-08-03 17:51:44 +02:00
parent dee00e7a02
commit 8e848394cd
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -8,7 +8,7 @@ use num_integer::div_mod_floor;
use minedmap::{ use minedmap::{
io::{fs, storage}, io::{fs, storage},
resource::block_color, resource::{block_color, Biome},
types::*, types::*,
}; };
@ -37,6 +37,27 @@ fn coord_offset<const AXIS: u8>(
) )
} }
fn biome_at(
region_group: &RegionGroup<ProcessedRegion>,
chunk: ChunkCoords,
block: LayerBlockCoords,
dx: i32,
dz: i32,
) -> Option<&Biome> {
let (region_x, chunk_x, block_x) = coord_offset(chunk.x, block.x, dx);
let (region_z, chunk_z, block_z) = coord_offset(chunk.z, block.z, dz);
let chunk = ChunkCoords {
x: chunk_x,
z: chunk_z,
};
let block = LayerBlockCoords {
x: block_x,
z: block_z,
};
let region = region_group.get(region_x, region_z)?;
region[chunk].as_ref()?.biomes[block].as_ref()
}
pub struct TileRenderer<'a> { pub struct TileRenderer<'a> {
config: &'a Config, config: &'a Config,
} }