From 8e848394cdb9f201742e5541a7f82660f389cc7c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 3 Aug 2023 17:51:44 +0200 Subject: [PATCH] minedmap/tile_renderer: add biome_at() helper Retrieve the biome at a given coordinate, possibly offset by a number of blocks. --- src/bin/minedmap/tile_renderer.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bin/minedmap/tile_renderer.rs b/src/bin/minedmap/tile_renderer.rs index 8988425..50105cd 100644 --- a/src/bin/minedmap/tile_renderer.rs +++ b/src/bin/minedmap/tile_renderer.rs @@ -8,7 +8,7 @@ use num_integer::div_mod_floor; use minedmap::{ io::{fs, storage}, - resource::block_color, + resource::{block_color, Biome}, types::*, }; @@ -37,6 +37,27 @@ fn coord_offset( ) } +fn biome_at( + region_group: &RegionGroup, + 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> { config: &'a Config, }