aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-09 13:29:59 -0600
committerGitHub <noreply@github.com>2025-12-09 13:29:59 -0600
commit26d619c9a329087a23d6577ee74bd764f50cd773 (patch)
tree8020fe902257764a23a445c6ed9987ea4848189d /azalea-chat/src
parent84cd261118c9d1e3145d4d1751c0d22098cd8cd8 (diff)
downloadazalea-drasl-26d619c9a329087a23d6577ee74bd764f50cd773.tar.xz
Enchantments (#286)
* start implementing enchants * store parsed registries * more work on enchants * implement deserializer for some entity effects * mostly working definitions for enchants * fix tests * detect equipment changes * fix errors * update changelog * fix some imports * remove outdated todo * add basic test for enchants applying attributes * use git simdnbt
Diffstat (limited to 'azalea-chat/src')
-rw-r--r--azalea-chat/src/component.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index aabb155f..c3cc5224 100644
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -5,13 +5,9 @@ use std::{
sync::LazyLock,
};
-#[cfg(feature = "azalea-buf")]
+#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
use serde::{Deserialize, Deserializer, Serialize, de};
-#[cfg(feature = "simdnbt")]
-use simdnbt::{Deserialize as _, FromNbtTag as _, Serialize as _};
-#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
-use tracing::{debug, trace, warn};
use crate::{
base_component::BaseComponent,
@@ -66,6 +62,8 @@ impl FormattedText {
#[cfg(feature = "simdnbt")]
fn parse_separator_nbt(nbt: &simdnbt::borrow::NbtCompound) -> Option<FormattedText> {
+ use simdnbt::FromNbtTag;
+
if let Some(separator) = nbt.get("separator") {
FormattedText::from_nbt_tag(separator)
} else {
@@ -461,6 +459,8 @@ impl FormattedText {
FormattedText::from(s)
}
fn from_nbt_list(list: simdnbt::borrow::NbtList) -> Option<FormattedText> {
+ use tracing::debug;
+
let mut component;
if let Some(compounds) = list.compounds() {
component = FormattedText::from_nbt_compound(compounds.first()?)?;
@@ -480,6 +480,9 @@ impl FormattedText {
}
pub fn from_nbt_compound(compound: simdnbt::borrow::NbtCompound) -> Option<Self> {
+ use simdnbt::{Deserialize, FromNbtTag};
+ use tracing::{trace, warn};
+
let mut component: FormattedText;
if let Some(text) = compound.get("text") {
@@ -631,6 +634,9 @@ impl From<&simdnbt::Mutf8Str> for FormattedText {
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
impl AzaleaRead for FormattedText {
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
+ use simdnbt::FromNbtTag;
+ use tracing::trace;
+
let nbt = simdnbt::borrow::read_optional_tag(buf)?;
trace!(
"Reading NBT for FormattedText: {:?}",
@@ -648,6 +654,8 @@ impl AzaleaRead for FormattedText {
#[cfg(all(feature = "azalea-buf", feature = "simdnbt"))]
impl AzaleaWrite for FormattedText {
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
+ use simdnbt::Serialize;
+
let mut out = Vec::new();
simdnbt::owned::BaseNbt::write_unnamed(&(self.clone().to_compound().into()), &mut out);
buf.write_all(&out)