world: implement top_layer function

Implement one of the core functions of MinedMap: finding the topmost
visible block at each coordinate.
This commit is contained in:
Matthias Schiffer 2023-02-18 11:51:24 +01:00
parent 2530a557a9
commit f48aa877d2
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 148 additions and 2 deletions

View file

@ -3,6 +3,8 @@ use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use minedmap::{resource, world};
#[derive(Debug, Parser)]
struct Args {
/// Filename to dump
@ -12,9 +14,22 @@ struct Args {
fn main() -> Result<()> {
let args = Args::parse();
let block_types = resource::block_types();
minedmap::io::region::from_file(args.file.as_path())?.foreach_chunk(
|coords, value: minedmap::world::de::Chunk| {
println!("Chunk {:?}: {:#?}", coords, value);
|coords, data: world::de::Chunk| {
let chunk = match world::chunk::Chunk::new(&data) {
Ok(chunk) => chunk,
Err(err) => {
eprintln!("Chunk {:?}: {}", coords, err);
return;
}
};
match world::layer::top_layer(&chunk, &block_types) {
Ok(_) => {}
Err(err) => println!("{:?}", err),
}
},
)
}