From 8e1c52aca5a93a14c386d75bc7b389a30a66d2f2 Mon Sep 17 00:00:00 2001 From: Andrew Brower Date: Tue, 19 Nov 2024 15:44:12 -0500 Subject: [PATCH] feat: modern art feature flag --- Cargo.toml | 1 + src/protocol/packets/play/world.rs | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96769b2..c92209e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ uuid = "1.11.0" default = [] compression = [] encryption = ["dep:cfb8", "dep:aes"] +modern_art = [] lan = [] full = ["compression", "encryption"] diff --git a/src/protocol/packets/play/world.rs b/src/protocol/packets/play/world.rs index 61f9a49..775ef5d 100644 --- a/src/protocol/packets/play/world.rs +++ b/src/protocol/packets/play/world.rs @@ -195,8 +195,11 @@ impl ChunkSection { pub fn anvil_to_sec(value: &world::Section, block_states: &Blocks) -> Self { let mut blocks: [i16; 16 * 16 * 16] = [0; 16 * 16 * 16]; let bit_length = (64 - (value.block_states.palette.len() as u64).leading_zeros()).max(4); + + #[cfg(not(feature = "modern_art"))] let blocks_per_long = 64 / bit_length; + #[cfg(not(feature = "modern_art"))] let bit_mask = (1 << bit_length) - 1; match value.block_states.data { @@ -204,10 +207,23 @@ impl ChunkSection { Some(ref data) => { let mut i = 0; for long in data.iter() { - let long = *long as u64; - for b in 0..blocks_per_long { - blocks[i] = ((long >> (bit_length * b)) & bit_mask) as i16; - i += 1; + #[cfg(not(feature = "modern_art"))] + { + let long = *long as u64; + for b in 0..blocks_per_long { + blocks[i] = ((long >> (bit_length * b)) & bit_mask) as i16; + i += 1; + } + } + + #[cfg(feature = "modern_art")] + { + let mut long = *long as u64; + while long != 0 { + blocks[i] = (long & ((1 << bit_length) - 1)) as i16; + long >>= bit_length; + i += 1; + } } } } -- 2.51.2