From 69e1125ecbb3e695125b8e65deba3e3f7be41b70 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 17 Jun 2022 15:59:27 -0500 Subject: [PATCH] Slightly improve bit storage --- .vscode/settings.json | 2 +- azalea-world/src/bit_storage.rs | 12 ++++++------ azalea-world/src/lib.rs | 4 ++++ bot/src/main.rs | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b0d07499..3b614348 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "editor.formatOnSave": false + "editor.formatOnSave": true } \ No newline at end of file diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs index c69cb216..0dc81f9a 100644 --- a/azalea-world/src/bit_storage.rs +++ b/azalea-world/src/bit_storage.rs @@ -77,8 +77,8 @@ pub struct BitStorage { mask: u64, size: usize, values_per_long: u8, - divide_mul: i32, - divide_add: i32, + divide_mul: u64, + divide_add: u64, divide_shift: i32, } @@ -138,16 +138,16 @@ impl BitStorage { mask, size, values_per_long: values_per_long as u8, - divide_mul, - divide_add, + divide_mul: divide_mul as u32 as u64, + divide_add: divide_add as u32 as u64, divide_shift, }) } pub fn cell_index(&self, index: u64) -> usize { // as unsigned wrap - let first = self.divide_mul as u32 as u64; - let second = self.divide_add as u64; + let first = self.divide_mul; + let second = self.divide_add; (((index * first) + second) >> 32 >> self.divide_shift) .try_into() diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 8777c0a3..26566416 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -205,12 +205,15 @@ pub struct Section { impl McBufReadable for Section { fn read_into(buf: &mut impl Read) -> Result { let block_count = u16::read_into(buf)?; + // this is commented out because the vanilla server is wrong // assert!( // block_count <= 16 * 16 * 16, // "A section has more blocks than what should be possible. This is a bug!" // ); + let states = PalettedContainer::read_with_type(buf, &PalettedContainerType::BlockStates)?; + for i in 0..states.storage.size() { if !BlockState::is_valid_state(states.storage.get(i) as u32) { return Err(format!( @@ -219,6 +222,7 @@ impl McBufReadable for Section { )); } } + let biomes = PalettedContainer::read_with_type(buf, &PalettedContainerType::Biomes)?; Ok(Section { block_count, diff --git a/bot/src/main.rs b/bot/src/main.rs index 8ad74ec4..cd27ba5a 100644 --- a/bot/src/main.rs +++ b/bot/src/main.rs @@ -6,7 +6,7 @@ async fn main() { println!("Hello, world!"); // let address = "95.111.249.143:10000"; - let address = "localhost:65519"; + let address = "localhost:51028"; // let response = azalea_client::ping::ping_server(&address.try_into().unwrap()) // .await // .unwrap();