aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTert0 <tert0byte@gmail.com>2025-10-10 23:19:33 +0200
committerGitHub <noreply@github.com>2025-10-10 16:19:33 -0500
commit1a1402954b07cd77615d0afc026c73b008787f51 (patch)
tree6b0488a0ff5c5bf7b1d90ef349c06fed810532f6
parentab507f7ac1c58e96bef26ba1f0e9066a35f841a7 (diff)
downloadazalea-drasl-1a1402954b07cd77615d0afc026c73b008787f51.tar.xz
Implement primitive translation arguments (#263)
* implement primitive translation arguments * add distinct number types to PrimitiveOrComponent * fix deserializing PrimitiveOrComponent::Boolean from nbt * improve nbt serialization for translatable component arguments
-rw-r--r--Cargo.lock42
-rw-r--r--azalea-chat/src/component.rs86
-rw-r--r--azalea-chat/src/translatable_component.rs212
-rw-r--r--azalea-protocol/src/packets/game/c_disguised_chat.rs8
-rw-r--r--azalea-protocol/src/packets/game/c_player_chat.rs8
5 files changed, 223 insertions, 133 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6a46064c..5453fc6a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -209,7 +209,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "azalea"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"anyhow",
"azalea-auth",
@@ -249,7 +249,7 @@ dependencies = [
[[package]]
name = "azalea-auth"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf",
"azalea-crypto",
@@ -271,7 +271,7 @@ dependencies = [
[[package]]
name = "azalea-block"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-block-macros",
"azalea-buf",
@@ -280,7 +280,7 @@ dependencies = [
[[package]]
name = "azalea-block-macros"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"proc-macro2",
"quote",
@@ -289,7 +289,7 @@ dependencies = [
[[package]]
name = "azalea-brigadier"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf",
"azalea-chat",
@@ -300,7 +300,7 @@ dependencies = [
[[package]]
name = "azalea-buf"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf-macros",
"byteorder",
@@ -314,7 +314,7 @@ dependencies = [
[[package]]
name = "azalea-buf-macros"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"proc-macro2",
"quote",
@@ -323,7 +323,7 @@ dependencies = [
[[package]]
name = "azalea-chat"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf",
"azalea-language",
@@ -336,7 +336,7 @@ dependencies = [
[[package]]
name = "azalea-client"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"anyhow",
"async-compat",
@@ -374,7 +374,7 @@ dependencies = [
[[package]]
name = "azalea-core"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf",
"azalea-chat",
@@ -393,7 +393,7 @@ dependencies = [
[[package]]
name = "azalea-crypto"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"aes",
"azalea-buf",
@@ -410,7 +410,7 @@ dependencies = [
[[package]]
name = "azalea-entity"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-auth",
"azalea-block",
@@ -434,7 +434,7 @@ dependencies = [
[[package]]
name = "azalea-inventory"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-auth",
"azalea-buf",
@@ -451,7 +451,7 @@ dependencies = [
[[package]]
name = "azalea-inventory-macros"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"proc-macro2",
"quote",
@@ -460,7 +460,7 @@ dependencies = [
[[package]]
name = "azalea-language"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"compact_str",
"serde_json",
@@ -468,7 +468,7 @@ dependencies = [
[[package]]
name = "azalea-physics"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-block",
"azalea-core",
@@ -485,7 +485,7 @@ dependencies = [
[[package]]
name = "azalea-protocol"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"anyhow",
"async-recursion",
@@ -521,7 +521,7 @@ dependencies = [
[[package]]
name = "azalea-protocol-macros"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"proc-macro2",
"quote",
@@ -530,7 +530,7 @@ dependencies = [
[[package]]
name = "azalea-registry"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-buf",
"azalea-registry-macros",
@@ -540,7 +540,7 @@ dependencies = [
[[package]]
name = "azalea-registry-macros"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"quote",
"syn",
@@ -548,7 +548,7 @@ dependencies = [
[[package]]
name = "azalea-world"
-version = "0.14.0+mc1.21.9"
+version = "0.14.0+mc1.21.10"
dependencies = [
"azalea-block",
"azalea-buf",
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 338c1def..87886e96 100644
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -17,7 +17,7 @@ use crate::{
base_component::BaseComponent,
style::{ChatFormatting, Style},
text_component::TextComponent,
- translatable_component::{StringOrComponent, TranslatableComponent},
+ translatable_component::{PrimitiveOrComponent, TranslatableComponent},
};
/// A chat component, basically anything you can see in chat.
@@ -306,26 +306,15 @@ impl<'de> Deserialize<'de> for FormattedText {
None
};
if let Some(with) = json.get("with") {
- let with = with
+ let with_array = with
.as_array()
- .ok_or_else(|| de::Error::custom("\"with\" must be an array"))?;
- let mut with_array = Vec::with_capacity(with.len());
- for item in with {
- // if it's a string component with no styling and no siblings, just add a
- // string to with_array otherwise add the component
- // to the array
- let c = FormattedText::deserialize(item).map_err(de::Error::custom)?;
- if let FormattedText::Text(text_component) = c
- && text_component.base.siblings.is_empty()
- && text_component.base.style.is_empty()
- {
- with_array.push(StringOrComponent::String(text_component.text));
- continue;
- }
- with_array.push(StringOrComponent::FormattedText(
- FormattedText::deserialize(item).map_err(de::Error::custom)?,
- ));
- }
+ .ok_or_else(|| de::Error::custom("\"with\" must be an array"))?
+ .iter()
+ .map(|item| {
+ PrimitiveOrComponent::deserialize(item).map_err(de::Error::custom)
+ })
+ .collect::<Result<Vec<PrimitiveOrComponent>, _>>()?;
+
component = FormattedText::Translatable(TranslatableComponent::with_fallback(
translate, fallback, with_array,
));
@@ -487,11 +476,11 @@ impl FormattedText {
if with_list.empty() {
} else if let Some(with) = with_list.strings() {
for item in with {
- with_array.push(StringOrComponent::String(item.to_string()));
+ with_array.push(PrimitiveOrComponent::String(item.to_string()));
}
} else if let Some(with) = with_list.ints() {
for item in with {
- with_array.push(StringOrComponent::String(item.to_string()));
+ with_array.push(PrimitiveOrComponent::Integer(item));
}
} else if let Some(with) = with_list.compounds() {
for item in with {
@@ -504,41 +493,39 @@ impl FormattedText {
// for the /give system messages
if let Some(b) = primitive.byte() {
// interpreted as boolean
- with_array.push(StringOrComponent::String(
- if b != 0 { "true" } else { "false" }.to_string(),
- ));
+ with_array.push(PrimitiveOrComponent::Boolean(b != 0));
} else if let Some(s) = primitive.short() {
- with_array.push(StringOrComponent::String(s.to_string()));
+ with_array.push(PrimitiveOrComponent::Short(s));
} else if let Some(i) = primitive.int() {
- with_array.push(StringOrComponent::String(i.to_string()));
+ with_array.push(PrimitiveOrComponent::Integer(i));
} else if let Some(l) = primitive.long() {
- with_array.push(StringOrComponent::String(l.to_string()));
+ with_array.push(PrimitiveOrComponent::Long(l));
} else if let Some(f) = primitive.float() {
- with_array.push(StringOrComponent::String(f.to_string()));
+ with_array.push(PrimitiveOrComponent::Float(f));
} else if let Some(d) = primitive.double() {
- with_array.push(StringOrComponent::String(d.to_string()));
+ with_array.push(PrimitiveOrComponent::Double(d));
} else if let Some(s) = primitive.string() {
- with_array.push(StringOrComponent::String(s.to_string()));
+ with_array.push(PrimitiveOrComponent::String(s.to_string()));
} else {
warn!(
"couldn't parse {item:?} as FormattedText because it has a disallowed primitive"
);
- with_array.push(StringOrComponent::String("?".to_string()));
+ with_array.push(PrimitiveOrComponent::String("?".to_string()));
}
} else if let Some(c) = FormattedText::from_nbt_compound(item) {
if let FormattedText::Text(text_component) = c
&& text_component.base.siblings.is_empty()
&& text_component.base.style.is_empty()
{
- with_array.push(StringOrComponent::String(text_component.text));
+ with_array.push(PrimitiveOrComponent::String(text_component.text));
continue;
}
- with_array.push(StringOrComponent::FormattedText(
+ with_array.push(PrimitiveOrComponent::FormattedText(
FormattedText::from_nbt_compound(item)?,
));
} else {
warn!("couldn't parse {item:?} as FormattedText");
- with_array.push(StringOrComponent::String("?".to_string()));
+ with_array.push(PrimitiveOrComponent::String("?".to_string()));
}
}
} else {
@@ -698,6 +685,7 @@ mod tests {
use serde_json::Value;
use super::*;
+ use crate::style::TextColor;
#[test]
fn deserialize_translation() {
@@ -710,8 +698,8 @@ mod tests {
FormattedText::Translatable(TranslatableComponent::new(
"translation.test.args".to_string(),
vec![
- StringOrComponent::String("a".to_string()),
- StringOrComponent::String("b".to_string())
+ PrimitiveOrComponent::String("a".to_string()),
+ PrimitiveOrComponent::String("b".to_string())
]
))
);
@@ -733,7 +721,7 @@ mod tests {
FormattedText::Translatable(TranslatableComponent::with_fallback(
"translation.test.undefined".to_string(),
Some("fallback: %s".to_string()),
- vec![StringOrComponent::String("a".to_string())]
+ vec![PrimitiveOrComponent::String("a".to_string())]
))
);
}
@@ -746,4 +734,26 @@ mod tests {
.unwrap();
assert!(FormattedText::deserialize(&j).is_err());
}
+ #[test]
+ fn deserialize_translation_primitive_args() {
+ let j: Value = serde_json::from_str(
+ r#"{"translate":"commands.list.players", "with": [1, 65536, "<players>", {"text": "unused", "color": "red"}]}"#,
+ )
+ .unwrap();
+ assert_eq!(
+ FormattedText::deserialize(&j).unwrap(),
+ FormattedText::Translatable(TranslatableComponent::new(
+ "commands.list.players".to_string(),
+ vec![
+ PrimitiveOrComponent::Short(1),
+ PrimitiveOrComponent::Integer(65536),
+ PrimitiveOrComponent::String("<players>".to_string()),
+ PrimitiveOrComponent::FormattedText(FormattedText::Text(
+ TextComponent::new("unused")
+ .with_style(Style::new().color(Some(TextColor::parse("red").unwrap())))
+ ))
+ ]
+ ))
+ );
+ }
}
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index b8e93245..13afe6b7 100644
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -1,24 +1,36 @@
use std::fmt::{self, Display};
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
#[cfg(feature = "simdnbt")]
-use simdnbt::Serialize as _;
+use simdnbt::ToNbtTag;
use crate::{FormattedText, base_component::BaseComponent, text_component::TextComponent};
-#[derive(Clone, Debug, PartialEq, Serialize)]
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
-pub enum StringOrComponent {
+pub enum PrimitiveOrComponent {
+ Boolean(bool),
+ Short(i16),
+ Integer(i32),
+ Long(i64),
+ Float(f32),
+ Double(f64),
String(String),
FormattedText(FormattedText),
}
#[cfg(feature = "simdnbt")]
-impl simdnbt::ToNbtTag for StringOrComponent {
+impl simdnbt::ToNbtTag for PrimitiveOrComponent {
fn to_nbt_tag(self) -> simdnbt::owned::NbtTag {
match self {
- StringOrComponent::String(s) => s.to_nbt_tag(),
- StringOrComponent::FormattedText(c) => c.to_nbt_tag(),
+ PrimitiveOrComponent::Boolean(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::Short(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::Integer(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::Long(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::Float(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::Double(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::String(value) => value.to_nbt_tag(),
+ PrimitiveOrComponent::FormattedText(value) => value.to_nbt_tag(),
}
}
}
@@ -33,43 +45,97 @@ pub struct TranslatableComponent {
#[serde(skip_serializing_if = "Option::is_none")]
pub fallback: Option<String>,
#[serde(rename = "with")]
- pub args: Vec<StringOrComponent>,
+ pub args: Vec<PrimitiveOrComponent>,
}
#[cfg(feature = "simdnbt")]
-fn serialize_args_as_nbt(args: &[StringOrComponent]) -> simdnbt::owned::NbtList {
- // if it's all strings then make it a string list
- // if it's all components then make it a compound list
- // if it's a mix then return an error
-
- use tracing::debug;
-
- let mut string_list = Vec::new();
- let mut compound_list = Vec::new();
-
- for arg in args {
- match arg {
- StringOrComponent::String(s) => {
- string_list.push(s.clone());
- }
- StringOrComponent::FormattedText(c) => {
- compound_list.push(c.clone().to_compound());
- }
+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;
}
}
- if !string_list.is_empty() && !compound_list.is_empty() {
- // i'm actually not sure what vanilla does here, so i just made it return the
- // string list
- debug!("Tried to serialize a TranslatableComponent with a mix of strings and components.");
- return string_list.into();
- }
-
- if !string_list.is_empty() {
- return string_list.into();
+ 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);
}
- compound_list.into()
+ compounds.into()
}
#[cfg(feature = "simdnbt")]
@@ -79,13 +145,13 @@ impl simdnbt::Serialize for TranslatableComponent {
compound.insert("translate", self.key);
compound.extend(self.base.style.to_compound());
- compound.insert("with", serialize_args_as_nbt(&self.args));
+ compound.insert("with", serialize_args_as_nbt(self.args));
compound
}
}
impl TranslatableComponent {
- pub fn new(key: String, args: Vec<StringOrComponent>) -> Self {
+ pub fn new(key: String, args: Vec<PrimitiveOrComponent>) -> Self {
Self {
base: BaseComponent::new(),
key,
@@ -97,7 +163,7 @@ impl TranslatableComponent {
pub fn with_fallback(
key: String,
fallback: Option<String>,
- args: Vec<StringOrComponent>,
+ args: Vec<PrimitiveOrComponent>,
) -> Self {
Self {
base: BaseComponent::new(),
@@ -142,7 +208,7 @@ impl TranslatableComponent {
.args
.get(matched)
.cloned()
- .unwrap_or_else(|| StringOrComponent::String("".to_string()));
+ .unwrap_or_else(|| PrimitiveOrComponent::String("".to_string()));
components.push(TextComponent::new(built_text.clone()));
built_text.clear();
@@ -160,7 +226,9 @@ impl TranslatableComponent {
&self
.args
.get((d - 1) as usize)
- .unwrap_or(&StringOrComponent::String("".to_string()))
+ .unwrap_or(&PrimitiveOrComponent::String(
+ "".to_string(),
+ ))
.to_string(),
);
} else {
@@ -217,20 +285,32 @@ impl Display for TranslatableComponent {
}
}
-impl Display for StringOrComponent {
+impl Display for PrimitiveOrComponent {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
- StringOrComponent::String(s) => write!(f, "{s}"),
- StringOrComponent::FormattedText(c) => write!(f, "{c}"),
+ PrimitiveOrComponent::Boolean(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::Short(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::Integer(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::Long(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::Float(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::Double(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::String(value) => write!(f, "{value}"),
+ PrimitiveOrComponent::FormattedText(value) => write!(f, "{value}"),
}
}
}
-impl From<StringOrComponent> for TextComponent {
- fn from(soc: StringOrComponent) -> Self {
+impl From<PrimitiveOrComponent> for TextComponent {
+ fn from(soc: PrimitiveOrComponent) -> Self {
match soc {
- StringOrComponent::String(s) => TextComponent::new(s),
- StringOrComponent::FormattedText(c) => TextComponent::new(c.to_string()),
+ PrimitiveOrComponent::String(value) => TextComponent::new(value),
+ PrimitiveOrComponent::Boolean(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::Short(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::Integer(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::Long(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::Float(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::Double(value) => TextComponent::new(value.to_string()),
+ PrimitiveOrComponent::FormattedText(value) => TextComponent::new(value.to_string()),
}
}
}
@@ -254,10 +334,10 @@ mod tests {
let c = TranslatableComponent::new(
"translation.test.complex".to_string(),
vec![
- StringOrComponent::String("a".to_string()),
- StringOrComponent::String("b".to_string()),
- StringOrComponent::String("c".to_string()),
- StringOrComponent::String("d".to_string()),
+ PrimitiveOrComponent::String("a".to_string()),
+ PrimitiveOrComponent::String("b".to_string()),
+ PrimitiveOrComponent::String("c".to_string()),
+ PrimitiveOrComponent::String("d".to_string()),
],
);
// so true mojang
@@ -271,10 +351,10 @@ mod tests {
let c = TranslatableComponent::new(
"translation.test.escape".to_string(),
vec![
- StringOrComponent::String("a".to_string()),
- StringOrComponent::String("b".to_string()),
- StringOrComponent::String("c".to_string()),
- StringOrComponent::String("d".to_string()),
+ PrimitiveOrComponent::String("a".to_string()),
+ PrimitiveOrComponent::String("b".to_string()),
+ PrimitiveOrComponent::String("c".to_string()),
+ PrimitiveOrComponent::String("d".to_string()),
],
);
assert_eq!(c.read().unwrap().to_string(), "%s %a %%s %%b".to_string());
@@ -284,10 +364,10 @@ mod tests {
let c = TranslatableComponent::new(
"translation.test.invalid".to_string(),
vec![
- StringOrComponent::String("a".to_string()),
- StringOrComponent::String("b".to_string()),
- StringOrComponent::String("c".to_string()),
- StringOrComponent::String("d".to_string()),
+ PrimitiveOrComponent::String("a".to_string()),
+ PrimitiveOrComponent::String("b".to_string()),
+ PrimitiveOrComponent::String("c".to_string()),
+ PrimitiveOrComponent::String("d".to_string()),
],
);
assert_eq!(c.read().unwrap().to_string(), "hi %".to_string());
@@ -297,10 +377,10 @@ mod tests {
let c = TranslatableComponent::new(
"translation.test.invalid2".to_string(),
vec![
- StringOrComponent::String("a".to_string()),
- StringOrComponent::String("b".to_string()),
- StringOrComponent::String("c".to_string()),
- StringOrComponent::String("d".to_string()),
+ PrimitiveOrComponent::String("a".to_string()),
+ PrimitiveOrComponent::String("b".to_string()),
+ PrimitiveOrComponent::String("c".to_string()),
+ PrimitiveOrComponent::String("d".to_string()),
],
);
assert_eq!(c.read().unwrap().to_string(), "hi % s".to_string());
@@ -310,7 +390,7 @@ mod tests {
fn test_undefined() {
let c = TranslatableComponent::new(
"translation.test.undefined".to_string(),
- vec![StringOrComponent::String("a".to_string())],
+ vec![PrimitiveOrComponent::String("a".to_string())],
);
assert_eq!(
c.read().unwrap().to_string(),
@@ -323,7 +403,7 @@ mod tests {
let c = TranslatableComponent::with_fallback(
"translation.test.undefined".to_string(),
Some("translation fallback: %s".to_string()),
- vec![StringOrComponent::String("a".to_string())],
+ vec![PrimitiveOrComponent::String("a".to_string())],
);
assert_eq!(
c.read().unwrap().to_string(),
diff --git a/azalea-protocol/src/packets/game/c_disguised_chat.rs b/azalea-protocol/src/packets/game/c_disguised_chat.rs
index 1242b3f7..e0225096 100644
--- a/azalea-protocol/src/packets/game/c_disguised_chat.rs
+++ b/azalea-protocol/src/packets/game/c_disguised_chat.rs
@@ -1,7 +1,7 @@
use azalea_buf::AzBuf;
use azalea_chat::{
FormattedText,
- translatable_component::{StringOrComponent, TranslatableComponent},
+ translatable_component::{PrimitiveOrComponent, TranslatableComponent},
};
use azalea_protocol_macros::ClientboundGamePacket;
@@ -26,11 +26,11 @@ impl ClientboundDisguisedChat {
let target = self.chat_type.target_name.clone();
let mut args = vec![
- StringOrComponent::FormattedText(sender),
- StringOrComponent::FormattedText(content),
+ PrimitiveOrComponent::FormattedText(sender),
+ PrimitiveOrComponent::FormattedText(content),
];
if let Some(target) = target {
- args.push(StringOrComponent::FormattedText(target));
+ args.push(PrimitiveOrComponent::FormattedText(target));
}
let translation_key = self.chat_type.translation_key();
diff --git a/azalea-protocol/src/packets/game/c_player_chat.rs b/azalea-protocol/src/packets/game/c_player_chat.rs
index d8056d12..1e65864c 100644
--- a/azalea-protocol/src/packets/game/c_player_chat.rs
+++ b/azalea-protocol/src/packets/game/c_player_chat.rs
@@ -3,7 +3,7 @@ use std::io::{self, Cursor, Write};
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
use azalea_chat::{
FormattedText,
- translatable_component::{StringOrComponent, TranslatableComponent},
+ translatable_component::{PrimitiveOrComponent, TranslatableComponent},
};
use azalea_core::bitset::BitSet;
use azalea_crypto::MessageSignature;
@@ -106,11 +106,11 @@ impl ClientboundPlayerChat {
let target = self.chat_type.target_name.clone();
let mut args = vec![
- StringOrComponent::FormattedText(sender),
- StringOrComponent::FormattedText(content),
+ PrimitiveOrComponent::FormattedText(sender),
+ PrimitiveOrComponent::FormattedText(content),
];
if let Some(target) = target {
- args.push(StringOrComponent::FormattedText(target));
+ args.push(PrimitiveOrComponent::FormattedText(target));
}
let translation_key = self.chat_type.translation_key();