mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +01:00
world/de: new module for deserialization data structures
The new structures contain only the fields that MinedMap needs.
This commit is contained in:
parent
8c34f74952
commit
6379472282
4 changed files with 122 additions and 2 deletions
|
@ -1,2 +1,3 @@
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
pub mod world;
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,3 +1,20 @@
|
||||||
fn main() {
|
use std::path::PathBuf;
|
||||||
println!("Hello, world!");
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Debug, Parser)]
|
||||||
|
struct Args {
|
||||||
|
/// Filename to dump
|
||||||
|
file: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
minedmap::io::region::from_file(args.file.as_path())?.foreach_chunk(
|
||||||
|
|coords, value: minedmap::world::de::Chunk| {
|
||||||
|
println!("Chunk {:?}: {:#?}", coords, value);
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
101
src/world/de.rs
Normal file
101
src/world/de.rs
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
//! Data structures used to deserialize Minecraft save data
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
/// Element of the `palette` list of 1.18+ [block states](BlockStatesV1_18)
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
pub struct BlockStatePaletteEntry {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 1.18+ `block_states` element found in a [section](SectionV1_18)
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct BlockStatesV1_18 {
|
||||||
|
pub palette: Vec<BlockStatePaletteEntry>,
|
||||||
|
pub data: Option<fastnbt::LongArray>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 1.18+ `biomes` element found in a [section](SectionV1_18)
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct BiomesV1_18 {
|
||||||
|
pub palette: Vec<String>,
|
||||||
|
pub data: Option<fastnbt::LongArray>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Element of the 1.18+ `sections` list found in a [Chunk]
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct SectionV1_18 {
|
||||||
|
#[serde(rename = "Y")]
|
||||||
|
pub y: i32,
|
||||||
|
pub block_states: BlockStatesV1_18,
|
||||||
|
pub biomes: BiomesV1_18,
|
||||||
|
#[serde(rename = "BlockLight")]
|
||||||
|
pub block_light: Option<fastnbt::ByteArray>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Version-specific part of a pre-1.18 [Section](SectionOld)
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum SectionOldVariants {
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
V1_13 {
|
||||||
|
block_states: fastnbt::LongArray,
|
||||||
|
palette: Vec<BlockStatePaletteEntry>,
|
||||||
|
},
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
Old {
|
||||||
|
blocks: fastnbt::ByteArray,
|
||||||
|
data: fastnbt::ByteArray,
|
||||||
|
},
|
||||||
|
Empty {},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pre-1.18 section element found in the [Level](LevelOld) compound
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
pub struct SectionOld {
|
||||||
|
pub y: i8,
|
||||||
|
pub block_light: Option<fastnbt::ByteArray>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub section: SectionOldVariants,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pre-1.18 biome fields found in the [Level](LevelOld) compound
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum BiomesOld {
|
||||||
|
IntArray(fastnbt::IntArray),
|
||||||
|
ByteArray(fastnbt::ByteArray),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `Level` compound element found in pre-1.18 [chunks](Chunk)
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
pub struct LevelOld {
|
||||||
|
#[serde(default)]
|
||||||
|
pub sections: Vec<SectionOld>,
|
||||||
|
pub biomes: Option<BiomesOld>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Version-specific part of a [Chunk] compound
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum ChunkVariants {
|
||||||
|
V1_18 {
|
||||||
|
sections: Vec<SectionV1_18>,
|
||||||
|
},
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
Old {
|
||||||
|
level: LevelOld,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toplevel compound element of a Minecraft chunk
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
pub struct Chunk {
|
||||||
|
pub data_version: Option<u32>,
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub chunk: ChunkVariants,
|
||||||
|
}
|
1
src/world/mod.rs
Normal file
1
src/world/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod de;
|
Loading…
Add table
Reference in a new issue