diff options
| author | mat <git@matdoes.dev> | 2025-01-12 22:43:37 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-01-12 22:43:37 +0000 |
| commit | a1435b3b951746a79561c24fd7bdab9324bd00df (patch) | |
| tree | 4b5f336bba33d5fc198f2a0dd2737eeac17dcf85 /azalea-inventory/src | |
| parent | 093c99a0715b242895e553341711065e82cb69f6 (diff) | |
| download | azalea-drasl-a1435b3b951746a79561c24fd7bdab9324bd00df.tar.xz | |
fix bugs with decoding/encoding DataComponentPatch
Diffstat (limited to 'azalea-inventory/src')
| -rw-r--r-- | azalea-inventory/src/components.rs | 11 | ||||
| -rw-r--r-- | azalea-inventory/src/slot.rs | 20 |
2 files changed, 18 insertions, 13 deletions
diff --git a/azalea-inventory/src/components.rs b/azalea-inventory/src/components.rs index e62288c6..2675bee4 100644 --- a/azalea-inventory/src/components.rs +++ b/azalea-inventory/src/components.rs @@ -305,8 +305,7 @@ pub enum AttributeModifierOperation { // circular dependency) #[derive(Clone, PartialEq, AzBuf)] pub struct AttributeModifier { - pub uuid: Uuid, - pub name: String, + pub id: ResourceLocation, pub amount: f64, pub operation: AttributeModifierOperation, } @@ -877,8 +876,12 @@ impl DataComponent for DamageResistant { pub struct Equippable { pub slot: EquipmentSlot, pub equip_sound: SoundEvent, - pub model: Option<ResourceLocation>, - pub allowed_entities: HolderSet<EntityKind, ResourceLocation>, + pub asset_id: Option<ResourceLocation>, + pub camera_overlay: Option<ResourceLocation>, + pub allowed_entities: Option<HolderSet<EntityKind, ResourceLocation>>, + pub dispensable: bool, + pub swappable: bool, + pub damage_on_hurt: bool, } impl DataComponent for Equippable { const KIND: DataComponentKind = DataComponentKind::Equippable; diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs index f541c54d..3ca38f56 100644 --- a/azalea-inventory/src/slot.rs +++ b/azalea-inventory/src/slot.rs @@ -1,12 +1,12 @@ use std::{ any::Any, - collections::HashMap, fmt, io::{Cursor, Write}, }; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_registry::DataComponentKind; +use indexmap::IndexMap; use crate::components::{self}; @@ -178,7 +178,7 @@ impl AzaleaWrite for ItemStack { /// and Azalea does not implement that yet. #[derive(Default)] pub struct DataComponentPatch { - components: HashMap<DataComponentKind, Option<Box<dyn components::EncodableDataComponent>>>, + components: IndexMap<DataComponentKind, Option<Box<dyn components::EncodableDataComponent>>>, } impl DataComponentPatch { @@ -238,7 +238,7 @@ impl AzaleaRead for DataComponentPatch { return Ok(DataComponentPatch::default()); } - let mut components = HashMap::new(); + let mut components = IndexMap::new(); for _ in 0..components_with_data_count { let component_kind = DataComponentKind::azalea_read(buf)?; let component_data = components::from_kind(component_kind, buf)?; @@ -256,8 +256,8 @@ impl AzaleaRead for DataComponentPatch { impl AzaleaWrite for DataComponentPatch { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - let mut components_with_data_count = 0; - let mut components_without_data_count = 0; + let mut components_with_data_count: u32 = 0; + let mut components_without_data_count: u32 = 0; for component in self.components.values() { if component.is_some() { components_with_data_count += 1; @@ -269,12 +269,14 @@ impl AzaleaWrite for DataComponentPatch { components_with_data_count.azalea_write_var(buf)?; components_without_data_count.azalea_write_var(buf)?; + let mut component_buf = Vec::new(); for (kind, component) in &self.components { if let Some(component) = component { kind.azalea_write(buf)?; - let mut component_buf = Vec::new(); - component.encode(&mut component_buf).unwrap(); - component_buf.azalea_write(buf)?; + + component_buf.clear(); + component.encode(&mut component_buf)?; + buf.write_all(&component_buf)?; } } @@ -290,7 +292,7 @@ impl AzaleaWrite for DataComponentPatch { impl Clone for DataComponentPatch { fn clone(&self) -> Self { - let mut components = HashMap::with_capacity(self.components.len()); + let mut components = IndexMap::with_capacity(self.components.len()); for (kind, component) in &self.components { components.insert(*kind, component.as_ref().map(|c| (*c).clone())); } |
