1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

fix bugs with decoding/encoding DataComponentPatch

This commit is contained in:
mat 2025-01-12 22:43:37 +00:00
parent 093c99a071
commit a1435b3b95
5 changed files with 51 additions and 14 deletions

1
Cargo.lock generated
View file

@ -428,6 +428,7 @@ dependencies = [
"azalea-core", "azalea-core",
"azalea-inventory-macros", "azalea-inventory-macros",
"azalea-registry", "azalea-registry",
"indexmap",
"simdnbt", "simdnbt",
"uuid", "uuid",
] ]

View file

@ -14,6 +14,7 @@ azalea-chat = { path = "../azalea-chat", version = "0.11.0", features = [
azalea-core = { path = "../azalea-core", version = "0.11.0" } azalea-core = { path = "../azalea-core", version = "0.11.0" }
azalea-inventory-macros = { path = "./azalea-inventory-macros", version = "0.11.0" } azalea-inventory-macros = { path = "./azalea-inventory-macros", version = "0.11.0" }
azalea-registry = { path = "../azalea-registry", version = "0.11.0" } azalea-registry = { path = "../azalea-registry", version = "0.11.0" }
indexmap = "2.7.0"
simdnbt = { workspace = true } simdnbt = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }

View file

@ -305,8 +305,7 @@ pub enum AttributeModifierOperation {
// circular dependency) // circular dependency)
#[derive(Clone, PartialEq, AzBuf)] #[derive(Clone, PartialEq, AzBuf)]
pub struct AttributeModifier { pub struct AttributeModifier {
pub uuid: Uuid, pub id: ResourceLocation,
pub name: String,
pub amount: f64, pub amount: f64,
pub operation: AttributeModifierOperation, pub operation: AttributeModifierOperation,
} }
@ -877,8 +876,12 @@ impl DataComponent for DamageResistant {
pub struct Equippable { pub struct Equippable {
pub slot: EquipmentSlot, pub slot: EquipmentSlot,
pub equip_sound: SoundEvent, pub equip_sound: SoundEvent,
pub model: Option<ResourceLocation>, pub asset_id: Option<ResourceLocation>,
pub allowed_entities: HolderSet<EntityKind, 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 { impl DataComponent for Equippable {
const KIND: DataComponentKind = DataComponentKind::Equippable; const KIND: DataComponentKind = DataComponentKind::Equippable;

View file

@ -1,12 +1,12 @@
use std::{ use std::{
any::Any, any::Any,
collections::HashMap,
fmt, fmt,
io::{Cursor, Write}, io::{Cursor, Write},
}; };
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
use azalea_registry::DataComponentKind; use azalea_registry::DataComponentKind;
use indexmap::IndexMap;
use crate::components::{self}; use crate::components::{self};
@ -178,7 +178,7 @@ impl AzaleaWrite for ItemStack {
/// and Azalea does not implement that yet. /// and Azalea does not implement that yet.
#[derive(Default)] #[derive(Default)]
pub struct DataComponentPatch { pub struct DataComponentPatch {
components: HashMap<DataComponentKind, Option<Box<dyn components::EncodableDataComponent>>>, components: IndexMap<DataComponentKind, Option<Box<dyn components::EncodableDataComponent>>>,
} }
impl DataComponentPatch { impl DataComponentPatch {
@ -238,7 +238,7 @@ impl AzaleaRead for DataComponentPatch {
return Ok(DataComponentPatch::default()); return Ok(DataComponentPatch::default());
} }
let mut components = HashMap::new(); let mut components = IndexMap::new();
for _ in 0..components_with_data_count { for _ in 0..components_with_data_count {
let component_kind = DataComponentKind::azalea_read(buf)?; let component_kind = DataComponentKind::azalea_read(buf)?;
let component_data = components::from_kind(component_kind, buf)?; let component_data = components::from_kind(component_kind, buf)?;
@ -256,8 +256,8 @@ impl AzaleaRead for DataComponentPatch {
impl AzaleaWrite for DataComponentPatch { impl AzaleaWrite for DataComponentPatch {
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
let mut components_with_data_count = 0; let mut components_with_data_count: u32 = 0;
let mut components_without_data_count = 0; let mut components_without_data_count: u32 = 0;
for component in self.components.values() { for component in self.components.values() {
if component.is_some() { if component.is_some() {
components_with_data_count += 1; components_with_data_count += 1;
@ -269,12 +269,14 @@ impl AzaleaWrite for DataComponentPatch {
components_with_data_count.azalea_write_var(buf)?; components_with_data_count.azalea_write_var(buf)?;
components_without_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 { for (kind, component) in &self.components {
if let Some(component) = component { if let Some(component) = component {
kind.azalea_write(buf)?; kind.azalea_write(buf)?;
let mut component_buf = Vec::new();
component.encode(&mut component_buf).unwrap(); component_buf.clear();
component_buf.azalea_write(buf)?; component.encode(&mut component_buf)?;
buf.write_all(&component_buf)?;
} }
} }
@ -290,7 +292,7 @@ impl AzaleaWrite for DataComponentPatch {
impl Clone for DataComponentPatch { impl Clone for DataComponentPatch {
fn clone(&self) -> Self { 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 { for (kind, component) in &self.components {
components.insert(*kind, component.as_ref().map(|c| (*c).clone())); components.insert(*kind, component.as_ref().map(|c| (*c).clone()));
} }

File diff suppressed because one or more lines are too long