From ef357fdf3667f3ded03203fc0f7cdec48a01ad8f Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 25 Mar 2025 11:17:39 -0500 Subject: 1.21.5 (#198) * 25w02a * move item_components codegen to a different module * remove outdated test * 25w03a * start updating to 24w09b * 1.21.5-pre2 * fix broken packets * 1.21.5-rc2 * merge main * delete unused acket_handling * 1.21.5 --- azalea-world/src/chunk_storage.rs | 22 ++++++---------------- azalea-world/src/heightmap.rs | 3 ++- azalea-world/src/palette.rs | 39 +++++++++------------------------------ 3 files changed, 17 insertions(+), 47 deletions(-) (limited to 'azalea-world/src') diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index db5ac877..d6243b87 100755 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -1,5 +1,4 @@ use std::collections::hash_map::Entry; -use std::str::FromStr; use std::{ collections::HashMap, fmt::Debug, @@ -13,7 +12,6 @@ use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; use azalea_core::position::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos}; use nohash_hasher::IntMap; use parking_lot::RwLock; -use simdnbt::owned::NbtCompound; use tracing::{debug, trace, warn}; use crate::heightmap::Heightmap; @@ -177,7 +175,7 @@ impl PartialChunkStorage { &mut self, pos: &ChunkPos, data: &mut Cursor<&[u8]>, - heightmaps: &NbtCompound, + heightmaps: &[(HeightmapKind, Box<[u64]>)], chunk_storage: &mut ChunkStorage, ) -> Result<(), BufReadError> { debug!("Replacing chunk at {:?}", pos); @@ -333,7 +331,7 @@ impl Chunk { buf: &mut Cursor<&[u8]>, dimension_height: u32, min_y: i32, - heightmaps_nbt: &NbtCompound, + heightmaps_data: &[(HeightmapKind, Box<[u64]>)], ) -> Result { let section_count = dimension_height / SECTION_HEIGHT; let mut sections = Vec::with_capacity(section_count as usize); @@ -344,18 +342,10 @@ impl Chunk { let sections = sections.into_boxed_slice(); let mut heightmaps = HashMap::new(); - for (name, heightmap) in heightmaps_nbt.iter() { - let Ok(kind) = HeightmapKind::from_str(&name.to_str()) else { - warn!("Unknown heightmap kind: {name}"); - continue; - }; - let Some(data) = heightmap.long_array() else { - warn!("Heightmap {name} is not a long array"); - continue; - }; + for (kind, data) in heightmaps_data { let data: Box<[u64]> = data.iter().map(|x| *x as u64).collect(); - let heightmap = Heightmap::new(kind, dimension_height, min_y, data); - heightmaps.insert(kind, heightmap); + let heightmap = Heightmap::new(*kind, dimension_height, min_y, data); + heightmaps.insert(*kind, heightmap); } Ok(Chunk { @@ -449,7 +439,7 @@ impl AzaleaRead for Section { let block_count = u16::azalea_read(buf)?; // this is commented out because the vanilla server is wrong - // ^ this comment was written ages ago. needs more investigation. + // TODO: ^ this comment was written ages ago. needs more investigation. // assert!( // block_count <= 16 * 16 * 16, // "A section has more blocks than what should be possible. This is a bug!" diff --git a/azalea-world/src/heightmap.rs b/azalea-world/src/heightmap.rs index f1ef30d2..00ebad41 100644 --- a/azalea-world/src/heightmap.rs +++ b/azalea-world/src/heightmap.rs @@ -1,6 +1,7 @@ use std::{fmt::Display, str::FromStr}; use azalea_block::BlockState; +use azalea_buf::AzBuf; use azalea_core::{math, position::ChunkBlockPos}; use azalea_registry::tags::blocks::LEAVES; @@ -8,7 +9,7 @@ use crate::{BitStorage, Section, chunk_storage::get_block_state_from_sections}; // (wg stands for worldgen) -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, AzBuf)] pub enum HeightmapKind { WorldSurfaceWg, WorldSurface, diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index 97786e7c..699ee2d5 100755 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -2,7 +2,6 @@ use std::io::{Cursor, Write}; use azalea_block::block_state::BlockStateIntegerRepr; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; -use azalea_core::math; use tracing::warn; use crate::BitStorage; @@ -45,37 +44,15 @@ impl PalettedContainer { buf: &mut Cursor<&[u8]>, container_type: &'static PalettedContainerKind, ) -> Result { - let server_bits_per_entry = u8::azalea_read(buf)?; - let palette_type = PaletteKind::from_bits_and_type(server_bits_per_entry, container_type); + let bits_per_entry = u8::azalea_read(buf)?; + let palette_type = PaletteKind::from_bits_and_type(bits_per_entry, container_type); let palette = palette_type.read(buf)?; let size = container_type.size(); - let data = Box::<[u64]>::azalea_read(buf)?; - - // we can only trust the bits per entry that we're sent if there's enough data - // that it'd be global. if it's not global, then we have to calculate it - // ourselves. - // this almost never matters, except on some custom servers like hypixel limbo - // TODO: this is incorrect. we should be getting the log2 of the max blockstate - // or biome instead of data.len(). this code might be causing wrong data to be - // read. ¯\_(ツ)_/¯ - let calculated_bits_per_entry = math::ceil_log2(data.len() as u32) as u8; - let calculated_bits_per_entry_palette_kind = - PaletteKind::from_bits_and_type(calculated_bits_per_entry, container_type); - let bits_per_entry = if calculated_bits_per_entry_palette_kind == PaletteKind::Global { - server_bits_per_entry - } else { - calculated_bits_per_entry - }; - - debug_assert!( - bits_per_entry != 0 || data.is_empty(), - "Bits per entry is 0 but data is not empty." - ); let mut storage = match BitStorage::new( - bits_per_entry.into(), + bits_per_entry as usize, size, - if data.is_empty() { + if bits_per_entry == 0 { Some(Box::new([])) } else { // we're going to update the data after creating the bitstorage @@ -90,9 +67,11 @@ impl PalettedContainer { )); } }; - // minecraft does this to allow the data to have extra padding bits. most - // servers don't use this, but it's notably used by hypixel. - storage.data = data; + + // now read the data + for i in 0..storage.data.len() { + storage.data[i] = u64::azalea_read(buf)?; + } Ok(PalettedContainer { bits_per_entry, -- cgit v1.2.3