From ef357fdf3667f3ded03203fc0f7cdec48a01ad8f Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 25 Mar 2025 11:17:39 -0500 Subject: 1.21.5 (#198) * 25w02a * move item_components codegen to a different module * remove outdated test * 25w03a * start updating to 24w09b * 1.21.5-pre2 * fix broken packets * 1.21.5-rc2 * merge main * delete unused acket_handling * 1.21.5 --- azalea-protocol/src/packets/game/c_player_chat.rs | 61 +++++++++++++---------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'azalea-protocol/src/packets/game/c_player_chat.rs') diff --git a/azalea-protocol/src/packets/game/c_player_chat.rs b/azalea-protocol/src/packets/game/c_player_chat.rs index 3628fa95..a9a57301 100644 --- a/azalea-protocol/src/packets/game/c_player_chat.rs +++ b/azalea-protocol/src/packets/game/c_player_chat.rs @@ -2,17 +2,20 @@ use std::io::{Cursor, Write}; use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_chat::{ - translatable_component::{StringOrComponent, TranslatableComponent}, FormattedText, + translatable_component::{StringOrComponent, TranslatableComponent}, }; use azalea_core::bitset::BitSet; use azalea_crypto::MessageSignature; use azalea_protocol_macros::ClientboundGamePacket; -use azalea_registry::{ChatType, OptionalRegistry}; +use azalea_registry::Holder; +use simdnbt::owned::NbtCompound; use uuid::Uuid; #[derive(Clone, Debug, AzBuf, ClientboundGamePacket, PartialEq)] pub struct ClientboundPlayerChat { + #[var] + pub global_index: u32, pub sender: Uuid, #[var] pub index: u32, @@ -52,34 +55,30 @@ pub enum FilterMask { PartiallyFiltered(BitSet), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, AzBuf)] pub struct ChatTypeBound { - pub chat_type: ChatType, + pub chat_type: Holder, pub name: FormattedText, pub target_name: Option, } -impl AzaleaRead for ChatTypeBound { - fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { - let Some(chat_type) = OptionalRegistry::::azalea_read(buf)?.0 else { - return Err(BufReadError::Custom("ChatType cannot be None".to_owned())); - }; - let name = FormattedText::azalea_read(buf)?; - let target_name = Option::::azalea_read(buf)?; - - Ok(ChatTypeBound { - chat_type, - name, - target_name, - }) - } + +#[derive(Clone, Debug, PartialEq, AzBuf)] +pub struct DirectChatType { + pub chat: ChatTypeDecoration, + pub narration: ChatTypeDecoration, } -impl AzaleaWrite for ChatTypeBound { - fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - OptionalRegistry(Some(self.chat_type)).azalea_write(buf)?; - self.name.azalea_write(buf)?; - self.target_name.azalea_write(buf)?; - Ok(()) - } +#[derive(Clone, Debug, PartialEq, AzBuf)] +pub struct ChatTypeDecoration { + pub translation_key: String, + pub parameters: Vec, + pub style: NbtCompound, +} + +#[derive(Clone, Copy, Debug, PartialEq, AzBuf)] +pub enum ChatTypeDecorationParameter { + Sender = 0, + Target = 1, + Content = 2, } // must be in Client @@ -106,8 +105,6 @@ impl ClientboundPlayerChat { let content = self.content(); let target = self.chat_type.target_name.clone(); - let translation_key = self.chat_type.chat_type.chat_translation_key(); - let mut args = vec![ StringOrComponent::FormattedText(sender), StringOrComponent::FormattedText(content), @@ -116,12 +113,22 @@ impl ClientboundPlayerChat { args.push(StringOrComponent::FormattedText(target)); } + let translation_key = self.chat_type.translation_key(); let component = TranslatableComponent::new(translation_key.to_string(), args); FormattedText::Translatable(component) } } +impl ChatTypeBound { + pub fn translation_key<'a>(&'a self) -> &'a str { + match &self.chat_type { + Holder::Reference(r) => r.chat_translation_key(), + Holder::Direct(d) => d.chat.translation_key.as_str(), + } + } +} + impl AzaleaRead for PackedMessageSignature { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let id = u32::azalea_read_var(buf)?; -- cgit v1.2.3