From 9c39e05d37926de13588777ecd84f34d2f6e0a1d Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 18 Aug 2025 16:42:48 -0545 Subject: fix ClientboundMerchantOffers --- azalea-inventory/src/components.rs | 10 +++++++--- azalea-inventory/src/slot.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'azalea-inventory/src') diff --git a/azalea-inventory/src/components.rs b/azalea-inventory/src/components.rs index 3da393e5..f63ca1ad 100644 --- a/azalea-inventory/src/components.rs +++ b/azalea-inventory/src/components.rs @@ -130,11 +130,15 @@ macro_rules! define_data_components { pub unsafe fn azalea_write_as( &self, kind: registry::DataComponentKind, - buf: &mut Vec, + buf: &mut impl std::io::Write, ) -> io::Result<()> { + let mut value = Vec::new(); match kind { - $( DataComponentKind::$x => unsafe { self.$x.encode(buf) }, )* - } + $( DataComponentKind::$x => unsafe { self.$x.encode(&mut value)? }, )* + }; + buf.write_all(&value)?; + + Ok(()) } /// # Safety /// diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs index e9da4856..2d4202e8 100644 --- a/azalea-inventory/src/slot.rs +++ b/azalea-inventory/src/slot.rs @@ -349,6 +349,17 @@ impl DataComponentPatch { ) }) } + /// Insert a new component into this patch, or mark a component as removed. + /// + /// # Safety + /// The [`DataComponentUnion`] must be of the correct kind. + pub unsafe fn unchecked_insert_component( + &mut self, + kind: DataComponentKind, + value: Option, + ) { + self.components.insert(kind, value); + } } impl Drop for DataComponentPatch { -- cgit v1.2.3