From 730297cf561d42fd9132eb201d1aec0d3d7c7e00 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 26 Sep 2025 06:16:33 +0800 Subject: fix compile error with new serde version, and update deps --- azalea-chat/src/click_event.rs | 47 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'azalea-chat/src/click_event.rs') diff --git a/azalea-chat/src/click_event.rs b/azalea-chat/src/click_event.rs index dddaff74..a61e2561 100644 --- a/azalea-chat/src/click_event.rs +++ b/azalea-chat/src/click_event.rs @@ -1,6 +1,6 @@ use serde::Serialize; #[cfg(feature = "simdnbt")] -use simdnbt::owned::Nbt; +use simdnbt::owned::{Nbt, NbtCompound, NbtTag}; #[derive(Clone, Debug, PartialEq, Serialize)] #[serde(rename_all = "snake_case", tag = "action")] @@ -31,3 +31,48 @@ pub enum ClickEvent { payload: Nbt, }, } + +#[cfg(feature = "simdnbt")] +impl simdnbt::Serialize for ClickEvent { + fn to_compound(self) -> NbtCompound { + let mut compound = NbtCompound::new(); + let mut action = |s: &str| { + compound.insert("action", s); + }; + match self { + ClickEvent::OpenUrl { url } => { + action("open_url"); + compound.insert("url", url); + } + ClickEvent::OpenFile { path } => { + action("open_file"); + compound.insert("path", path); + } + ClickEvent::RunCommand { command } => { + action("run_command"); + compound.insert("command", command); + } + ClickEvent::SuggestCommand { command } => { + action("suggest_command"); + compound.insert("command", command); + } + ClickEvent::ShowDialog => { + action("show_dialog"); + } + ClickEvent::ChangePage { page } => { + action("change_page"); + compound.insert("page", NbtTag::Int(page)); + } + ClickEvent::CopyToClipboard { value } => { + action("copy_to_clipboard"); + compound.insert("value", value); + } + ClickEvent::Custom { id, payload } => { + action("custom"); + compound.insert("id", id); + compound.insert("payload", (**payload).clone()); + } + } + compound + } +} -- cgit v1.2.3