Skip to content

Commit 8fd11c1

Browse files
committed
fix incorrect PalettedContainer::write impl
1 parent 341e994 commit 8fd11c1

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

azalea-client/src/plugins/packet/relative_updates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn should_apply_entity_update(
107107

108108
let this_client_updates_received = partial_entity_infos
109109
.updates_received
110-
.get(&minecraft_entity_id)
110+
.get(minecraft_entity_id)
111111
.copied();
112112

113113
let can_update = if let Some(updates_received) = updates_received {

azalea-entity/src/plugin/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ pub fn update_dimensions(
231231
}
232232
}
233233

234+
#[allow(clippy::type_complexity)]
234235
pub fn update_crouching(
235236
query: Query<(&mut Crouching, &Pose), (Without<LocalEntity>, With<Player>)>,
236237
) {

azalea-world/src/bit_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const MAGIC: [(i32, i32, u32); 64] = [
7171
];
7272

7373
/// A compact list of integers with the given number of bits per entry.
74-
#[derive(Clone, Debug, Default)]
74+
#[derive(Clone, Debug, Default, PartialEq)]
7575
pub struct BitStorage {
7676
pub data: Box<[u64]>,
7777
bits: usize,

azalea-world/src/chunk_storage.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct Chunk {
7979
}
8080

8181
/// A section of a chunk, i.e. a 16*16*16 block area.
82-
#[derive(Clone, Debug, Default)]
82+
#[derive(Clone, Debug, Default, PartialEq)]
8383
pub struct Section {
8484
/// The number of non-empty blocks in the section, as sent to us by the
8585
/// server.
@@ -579,6 +579,7 @@ pub fn section_index(y: i32, min_y: i32) -> u32 {
579579
#[cfg(test)]
580580
mod tests {
581581
use super::*;
582+
use crate::palette::SectionPos;
582583

583584
#[test]
584585
fn test_section_index() {
@@ -639,4 +640,33 @@ mod tests {
639640
ChunkPos::new(2, -1),
640641
);
641642
}
643+
644+
#[test]
645+
fn serialize_and_deserialize_section() {
646+
let mut states = PalettedContainer::new();
647+
648+
states.set(
649+
SectionPos::new(1, 2, 3),
650+
BlockState::try_from(BlockState::MAX_STATE).unwrap(),
651+
);
652+
states.set(
653+
SectionPos::new(4, 5, 6),
654+
BlockState::try_from(BlockState::MAX_STATE).unwrap(),
655+
);
656+
let biomes = PalettedContainer::new();
657+
let section = Section {
658+
block_count: 2,
659+
states,
660+
biomes,
661+
};
662+
663+
let mut buf = Vec::new();
664+
section.azalea_write(&mut buf).unwrap();
665+
666+
let mut cur = Cursor::new(buf.as_slice());
667+
let deserialized_section = Section::azalea_read(&mut cur).unwrap();
668+
assert_eq!(cur.position(), buf.len() as u64);
669+
670+
assert_eq!(section, deserialized_section);
671+
}
642672
}

azalea-world/src/palette/container.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing::{debug, warn};
1212
use super::{Palette, PaletteKind};
1313
use crate::BitStorage;
1414

15-
#[derive(Clone, Debug)]
15+
#[derive(Clone, Debug, PartialEq)]
1616
pub struct PalettedContainer<S: PalletedContainerKind> {
1717
pub bits_per_entry: u8,
1818
/// This is usually a list of unique values that appear in the container so
@@ -25,7 +25,9 @@ pub struct PalettedContainer<S: PalletedContainerKind> {
2525
pub storage: BitStorage,
2626
}
2727

28-
pub trait PalletedContainerKind: Copy + Clone + Debug + Default + TryFrom<u32> + Into<u32> {
28+
pub trait PalletedContainerKind:
29+
Copy + Clone + Debug + Default + PartialEq + TryFrom<u32> + Into<u32>
30+
{
2931
type SectionPos: SectionPos;
3032

3133
fn size_bits() -> usize;
@@ -295,7 +297,10 @@ impl<S: PalletedContainerKind> PalettedContainer<S> {
295297
pub fn write(&self, buf: &mut impl Write) -> io::Result<()> {
296298
self.bits_per_entry.azalea_write(buf)?;
297299
self.palette.write(buf)?;
298-
self.storage.data.azalea_write(buf)?;
300+
for word in &self.storage.data {
301+
word.azalea_write(buf)?;
302+
}
303+
299304
Ok(())
300305
}
301306
}

azalea-world/src/palette/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use azalea_buf::{AzBufVar, BufReadError};
1212
pub use container::*;
1313

1414
/// A representation of the different types of chunk palettes Minecraft uses.
15-
#[derive(Clone, Debug)]
15+
#[derive(Clone, Debug, PartialEq)]
1616
pub enum Palette<S: PalletedContainerKind> {
1717
/// ID of the corresponding entry in its global palette
1818
SingleValue(S),

0 commit comments

Comments
 (0)