Skip to content

Conversation

tal5
Copy link
Contributor

@tal5 tal5 commented Sep 10, 2025

Adds UnsafeValues#deserializeItemHover, to de-serialize an adventure ShowItem into an ItemStack.

My use case for this is a custom component serializer implementation (similar idea to MiniMessage), that needs to get an ItemStack instance for its serialization logic (I'm aware there may be better methods to implement this, but the serializer already exists and is in use with Bungee chat, I'm just migrating it to adventure & need to maintain the exact same format and behavior).

See discussion starting at https://discord.com/channels/289587909051416579/555462289851940864/1415331111856508980 (and specifically with lynx at https://discord.com/channels/289587909051416579/555462289851940864/1415336667237060650).

Note

This can throw some exceptions for invalid ShowItem data (e.g. uses Registry#getOrThrow), didn't really bother with that too much as it's an UnsafeValues use at your own risk, but let me know if you'd want more specific docs still/to catch them and return null.

@tal5 tal5 requested a review from a team as a code owner September 10, 2025 16:12
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Sep 10, 2025
@Override
public ItemStack deserializeItemHover(final HoverEvent.ShowItem itemHover) {
if (itemHover.dataComponents().isEmpty()) {
return ItemStack.of(Registry.MATERIAL.getOrThrow(itemHover.item()), itemHover.count());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this should be using this registry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used Material as that's what ItemStack.of takes, should I switch to ItemType with #createItemStack?
And if so, should I switch to the full RegistryAccess.registryAccess().getRegistry() or are the Registry.ITEM constants fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now uses Registry.ITEM with #createItemStack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Awaiting review
Development

Successfully merging this pull request may close these issues.

2 participants