fix 1.21.5 item and entity hover

This commit is contained in:
Alexander Medvedev 2025-04-06 14:07:17 +02:00
parent 80e6da9ffb
commit 67f26cf9bd
3 changed files with 10 additions and 13 deletions

View File

@ -296,7 +296,8 @@ pub(crate) fn build() -> TokenStream {
#constants
pub fn translated_name(&self) -> TextComponent {
serde_json::from_str(self.components.item_name.unwrap()).expect("Could not parse item name.")
// TODO
TextComponent::text(self.components.item_name.unwrap())
}
#[doc = "Try to parse an item from a resource location string."]

View File

@ -16,18 +16,16 @@ pub enum HoverEvent {
/// Number of the items in the stack
#[serde(default, skip_serializing_if = "Option::is_none")]
count: Option<i32>,
/// NBT information about the item (sNBT format)
#[serde(default, skip_serializing_if = "Option::is_none")]
tag: Option<Cow<'static, str>>,
// #[serde(default, skip_serializing_if = "Option::is_none")]
// components: Option<Cow<'static, str>>,
},
/// Shows an entity.
ShowEntity {
/// The entity's ID Entity Type
id: Cow<'static, str>,
/// The entity's UUID
/// The UUID cannot use uuid::Uuid because its serialization parses it into bytes, so its double bytes serialized
id: Cow<'static, str>,
/// Resource identifier of the entity
#[serde(default, skip_serializing_if = "Option::is_none")]
r#type: Option<Cow<'static, str>>,
uuid: Cow<'static, str>,
/// Optional custom name for the entity
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<Vec<TextComponentBase>>,
@ -40,13 +38,13 @@ impl HoverEvent {
value: vec![text.0],
}
}
pub fn show_entity<P>(id: P, kind: P, name: Option<TextComponent>) -> Self
pub fn show_entity<P>(uuid: P, kind: P, name: Option<TextComponent>) -> Self
where
P: Into<Cow<'static, str>>,
{
Self::ShowEntity {
id: id.into(),
r#type: Some(kind.into()),
id: kind.into(),
uuid: uuid.into(),
name: match name {
Some(name) => Some(vec![name.0]),
None => None,

View File

@ -67,7 +67,6 @@ impl CommandExecutor for Executor {
.hover_event(HoverEvent::ShowItem {
id: item_name.to_string().into(),
count: Some(item_count),
tag: None,
}),
TextComponent::text(targets[0].gameprofile.name.to_string())
.hover_event(HoverEvent::show_entity(
@ -97,7 +96,6 @@ impl CommandExecutor for Executor {
.hover_event(HoverEvent::ShowItem {
id: item_name.to_string().into(),
count: Some(item_count),
tag: None,
}),
TextComponent::text(targets.len().to_string()),
],