diff options
| author | mat <git@matdoes.dev> | 2025-10-12 23:01:54 +0300 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-10-12 23:01:54 +0300 |
| commit | ee2575794e91b9457a74a95daf1dcc707058cd58 (patch) | |
| tree | df725850ef18ded5ce3f6552e17095d0f704ae84 /azalea-chat/src/translatable_component.rs | |
| parent | 1a1402954b07cd77615d0afc026c73b008787f51 (diff) | |
| download | azalea-drasl-ee2575794e91b9457a74a95daf1dcc707058cd58.tar.xz | |
upgrade deps and clean up lots of doc comments
Diffstat (limited to 'azalea-chat/src/translatable_component.rs')
| -rw-r--r-- | azalea-chat/src/translatable_component.rs | 98 |
1 files changed, 10 insertions, 88 deletions
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs index 13afe6b7..ae1d80bc 100644 --- a/azalea-chat/src/translatable_component.rs +++ b/azalea-chat/src/translatable_component.rs @@ -2,7 +2,10 @@ use std::fmt::{self, Display}; use serde::{Deserialize, Serialize}; #[cfg(feature = "simdnbt")] -use simdnbt::ToNbtTag; +use simdnbt::{ + ToNbtTag, + owned::{NbtList, NbtTag}, +}; use crate::{FormattedText, base_component::BaseComponent, text_component::TextComponent}; @@ -49,93 +52,12 @@ pub struct TranslatableComponent { } #[cfg(feature = "simdnbt")] -fn serialize_args_as_nbt(args: Vec<PrimitiveOrComponent>) -> simdnbt::owned::NbtList { - let tags: Vec<simdnbt::owned::NbtTag> = args.into_iter().map(|arg| arg.to_nbt_tag()).collect(); - - if let Some(first_element) = tags.first() { - let tags = tags.clone(); - let homogenous_list = match first_element { - simdnbt::owned::NbtTag::Byte(_) => tags - .into_iter() - .map(|tag| tag.into_byte()) - .collect::<Option<Vec<i8>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Short(_) => tags - .into_iter() - .map(|tag| tag.into_short()) - .collect::<Option<Vec<i16>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Int(_) => tags - .into_iter() - .map(|tag| tag.into_int()) - .collect::<Option<Vec<i32>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Long(_) => tags - .into_iter() - .map(|tag| tag.into_long()) - .collect::<Option<Vec<i64>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Float(_) => tags - .into_iter() - .map(|tag| tag.into_float()) - .collect::<Option<Vec<f32>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Double(_) => tags - .into_iter() - .map(|tag| tag.into_double()) - .collect::<Option<Vec<f64>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::ByteArray(_) => tags - .into_iter() - .map(|tag| tag.into_byte_array()) - .collect::<Option<Vec<Vec<u8>>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::String(_) => tags - .into_iter() - .map(|tag| tag.into_string()) - .collect::<Option<Vec<simdnbt::Mutf8String>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::List(_) => tags - .into_iter() - .map(|tag| tag.into_list()) - .collect::<Option<Vec<simdnbt::owned::NbtList>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::Compound(_) => tags - .into_iter() - .map(|tag| tag.into_compound()) - .collect::<Option<Vec<simdnbt::owned::NbtCompound>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::IntArray(_) => tags - .into_iter() - .map(|tag| tag.into_int_array()) - .collect::<Option<Vec<Vec<i32>>>>() - .map(simdnbt::owned::NbtList::from), - simdnbt::owned::NbtTag::LongArray(_) => tags - .into_iter() - .map(|tag| tag.into_long_array()) - .collect::<Option<Vec<Vec<i64>>>>() - .map(simdnbt::owned::NbtList::from), - }; - - if let Some(homogenous_list) = homogenous_list { - return homogenous_list; - } - } - - let mut compounds = Vec::with_capacity(tags.len()); - for tag in tags { - let compound = if let simdnbt::owned::NbtTag::Compound(compound) = tag { - compound - } else { - let mut compound = simdnbt::owned::NbtCompound::new(); - compound.insert("", tag); - compound - }; - - compounds.push(compound); - } - - compounds.into() +fn serialize_args_as_nbt(args: Vec<PrimitiveOrComponent>) -> NbtList { + let tags = args + .into_iter() + .map(|arg| arg.to_nbt_tag()) + .collect::<Vec<NbtTag>>(); + NbtList::from(tags) } #[cfg(feature = "simdnbt")] |
