From 63b1036a96c45b0fefc6ca2501f1cc479acc95de Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 21 Feb 2025 17:22:00 +0000 Subject: fix CustomModelData and WrittenBookContent datacomponents --- azalea-core/src/filterable.rs | 55 +++++++++++++++++++++++++++++++++++++++++++ azalea-core/src/lib.rs | 1 + 2 files changed, 56 insertions(+) create mode 100644 azalea-core/src/filterable.rs (limited to 'azalea-core/src') diff --git a/azalea-core/src/filterable.rs b/azalea-core/src/filterable.rs new file mode 100644 index 00000000..70b0d6f7 --- /dev/null +++ b/azalea-core/src/filterable.rs @@ -0,0 +1,55 @@ +use std::io::Cursor; + +use azalea_buf::{AzaleaRead, AzaleaReadLimited, AzaleaReadVar, AzaleaWrite}; + +/// Used for written books. +pub struct Filterable { + pub raw: T, + pub filtered: Option, +} + +impl azalea_buf::AzaleaWrite for Filterable { + fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { + self.raw.azalea_write(buf)?; + self.filtered.azalea_write(buf)?; + Ok(()) + } +} +impl azalea_buf::AzaleaRead for Filterable { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { + let raw = AzaleaRead::azalea_read(buf)?; + let filtered = AzaleaRead::azalea_read(buf)?; + Ok(Self { raw, filtered }) + } +} +impl azalea_buf::AzaleaReadLimited for Filterable { + fn azalea_read_limited( + buf: &mut Cursor<&[u8]>, + limit: usize, + ) -> Result { + let raw = AzaleaReadLimited::azalea_read_limited(buf, limit)?; + let filtered = AzaleaReadLimited::azalea_read_limited(buf, limit)?; + Ok(Self { raw, filtered }) + } +} +impl azalea_buf::AzaleaReadVar for Filterable { + fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { + let raw = AzaleaReadVar::azalea_read_var(buf)?; + let filtered = AzaleaReadVar::azalea_read_var(buf)?; + Ok(Self { raw, filtered }) + } +} + +impl Clone for Filterable { + fn clone(&self) -> Self { + Self { + raw: self.raw.clone(), + filtered: self.filtered.clone(), + } + } +} +impl PartialEq for Filterable { + fn eq(&self, other: &Self) -> bool { + self.raw == other.raw && self.filtered == other.filtered + } +} diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs index 81dbf684..ba6d61ef 100755 --- a/azalea-core/src/lib.rs +++ b/azalea-core/src/lib.rs @@ -9,6 +9,7 @@ pub mod data_registry; pub mod delta; pub mod difficulty; pub mod direction; +pub mod filterable; pub mod game_type; pub mod math; pub mod objectives; -- cgit v1.2.3