start adding azalea-world

This commit is contained in:
mat 2022-05-01 18:59:07 -05:00
parent c2262a2123
commit 4d75415130
7 changed files with 63 additions and 1 deletions

4
Cargo.lock generated
View file

@ -164,6 +164,10 @@ dependencies = [
"uuid",
]
[[package]]
name = "azalea-world"
version = "0.1.0"
[[package]]
name = "bitflags"
version = "1.3.2"

View file

@ -10,6 +10,7 @@ members = [
"azalea-nbt",
"azalea-brigadier",
"azalea-crypto",
"azalea-world",
]
[profile.release]

View file

@ -233,6 +233,7 @@ impl Client {
}
GamePacket::ClientboundLevelChunkWithLightPacket(p) => {
println!("Got chunk with light packet {} {}", p.x, p.z);
// p.chunk_data
}
GamePacket::ClientboundLightUpdatePacket(p) => {
println!("Got light update packet {:?}", p);

View file

@ -30,5 +30,7 @@ pub struct BlockEntity {
pub struct ChunkSection {}
impl ClientboundLevelChunkPacketData {
pub fn read(world_height: u32) {}
pub fn read(world_height: u32) {
// let section_count
}
}

8
azalea-world/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "azalea-world"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
azalea-world/README.md Normal file
View file

@ -0,0 +1,3 @@
# Azalea World
The Minecraft world representation used in Azalea.

43
azalea-world/src/lib.rs Normal file
View file

@ -0,0 +1,43 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
}
pub struct Chunk {
sections: Vec<Section>,
}
pub struct Section {
states: PalettedContainer,
biomes: PalettedContainer,
}
pub struct PalettedContainer {
bits_per_entry: u8,
palette: Palette,
/// Compacted list of indices pointing to entry IDs in the Palette.
data: Vec<i64>,
}
pub enum Palette {
/// ID of the corresponding entry in its global palette
SingleValue(u32),
LinearPalette(Vec<u32>),
HashmapPalette(Vec<u32>),
GlobalPalette,
}
impl Palette {
fn choose_palette_for_states(bits_per_entry: u8) -> &'static Palette {
match bits_per_entry {
0 => &Palette::SingleValue,
1..=4 => &Palette::LinearPalette,
5..=8 => &Palette::HashmapPalette,
_ => &Palette::GlobalPalette,
}
}
}