azalea_chat/
hover_event.rs1use serde::Serialize;
2#[cfg(feature = "simdnbt")]
3use simdnbt::owned::NbtCompound;
4
5use crate::FormattedText;
6
7#[derive(Clone, Debug, PartialEq, Serialize)]
8#[serde(rename_all = "snake_case", tag = "action")]
9pub enum HoverEvent {
10 ShowText {
11 value: Box<FormattedText>,
12 },
13 ShowItem {
15 },
17 ShowEntity {
18 id: i32,
19 name: Box<FormattedText>,
21 },
22}
23
24#[cfg(feature = "simdnbt")]
25impl simdnbt::Serialize for HoverEvent {
26 fn to_compound(self) -> NbtCompound {
27 let mut compound = NbtCompound::new();
28 let mut action = |s: &str| {
29 compound.insert("action", s);
30 };
31 match self {
32 HoverEvent::ShowText { value } => {
33 action("show_text");
34 compound.insert("value", value.to_compound());
35 }
36 HoverEvent::ShowItem { .. } => {
37 action("show_item");
38 }
39 HoverEvent::ShowEntity { id, name } => {
40 action("show_entity");
41 compound.insert("id", id);
42 compound.insert("name", name.to_compound());
44 }
45 }
46 compound
47 }
48}