diff options
| author | mat <git@matdoes.dev> | 2025-02-21 17:22:00 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-21 17:22:00 +0000 |
| commit | 63b1036a96c45b0fefc6ca2501f1cc479acc95de (patch) | |
| tree | a0a06a5b1111d335c4e3c92695a3673f534a7769 /azalea-core/src | |
| parent | c285fadd34df2a43a5cfe1d3c02a3cc47bf69e9e (diff) | |
| download | azalea-drasl-63b1036a96c45b0fefc6ca2501f1cc479acc95de.tar.xz | |
fix CustomModelData and WrittenBookContent datacomponents
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/filterable.rs | 55 | ||||
| -rwxr-xr-x | azalea-core/src/lib.rs | 1 |
2 files changed, 56 insertions, 0 deletions
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<T> { + pub raw: T, + pub filtered: Option<T>, +} + +impl<T: AzaleaWrite> azalea_buf::AzaleaWrite for Filterable<T> { + 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<T: AzaleaRead> azalea_buf::AzaleaRead for Filterable<T> { + fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { + let raw = AzaleaRead::azalea_read(buf)?; + let filtered = AzaleaRead::azalea_read(buf)?; + Ok(Self { raw, filtered }) + } +} +impl<T: AzaleaReadLimited> azalea_buf::AzaleaReadLimited for Filterable<T> { + fn azalea_read_limited( + buf: &mut Cursor<&[u8]>, + limit: usize, + ) -> Result<Self, azalea_buf::BufReadError> { + let raw = AzaleaReadLimited::azalea_read_limited(buf, limit)?; + let filtered = AzaleaReadLimited::azalea_read_limited(buf, limit)?; + Ok(Self { raw, filtered }) + } +} +impl<T: AzaleaReadVar> azalea_buf::AzaleaReadVar for Filterable<T> { + fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { + let raw = AzaleaReadVar::azalea_read_var(buf)?; + let filtered = AzaleaReadVar::azalea_read_var(buf)?; + Ok(Self { raw, filtered }) + } +} + +impl<T: Clone> Clone for Filterable<T> { + fn clone(&self) -> Self { + Self { + raw: self.raw.clone(), + filtered: self.filtered.clone(), + } + } +} +impl<T: PartialEq> PartialEq for Filterable<T> { + 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; |
