-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ItemStack#displayName only return the display name #9050
base: master
Are you sure you want to change the base?
Conversation
Previously additional formatting like brackets around it and hover event was automatically added. This did not match the API specification and made it impossible to get the "raw" display name component without any additional data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that says nothing about additional characters or hover information
This is a documentation issue, not a reason to change the behavior of a method that's been around for multiple major versions out of the blue.
The method is named correctly, and returning the displayName as used in vanilla commands is 100% the intended behavior (as noted in the PR adding the method, however again I agree the docs are too light), if anything the displayName methods on ItemMeta are the ones named wrong, they should be called customName.
I think a hoverName utility method could be useful... although it looks like we closed a similar PR before: #8793
I do not agree with this just being a documentation issue. If anything this is an API design issue as the method is returning information that is clearly not a name: It's adding additional formatting not part of the name (the brackets around the name) as well as information unnecessary for the purpose the method appears to be for: To provide the displayed name of the ItemStack. Also besides what is claimed on the linked PR this is not something that you can easily do in a different way as Also in general: I don't think that the API should follow what Mojang calls internal methods/properties as here a usable and user-friendly API should be designed (and imo that includes using obvious and non-confusing names), something that Mojang doesn't need to think about. So just because Mojang calls it a "display name" and the other thing a "hover name" (something that doesn't even make sense imo. and shouldn't be exposed in the API under that name at all) it doesn't mean we need to use their wording if it doesn't fit in the overall plugin API. I realise that changing behaviour sucks and that this should've been caught back when it was first implemented but it wasn't and now we are here. And if the goal is to not break backwards compatibility here then of course A method providing the current implementation could be called something like |
deprecating displayName would be preferrable to blindly changing the behavior which has been set forth randomly during the middle of a patch release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, the name is kinda meh, but I agree that this is rather weird behavior.
@jpenilla can you take a look at this again (or someone else say what the state is here? 👀) |
Is there any chance for something like this getting pulled? Or is this feature just not getting accepted? Don't really want to waste time updating this to 1.20 if the whole thing isn't wanted... |
The original logic we had when talking about this was to create a distinction between a "display name" (the item name formatted for use in a command output like Vanilla has) and a "custom name" which is just the What you seem to be hoping for is a third thing, the custom name if present or otherwise the translation key ( Does paper api expose all 3 of these? imo the best way forward is to add the missing concepts to the API without renaming/changing behavior on anything that currently exists. The end naming might not be ideal, but hopefully JD can help users navigate their options. |
I think the best way forward would be to express the logic you are after (which I 100% agree, this is functionality used so often, API sugar is useful) in a new method, maybe named If you are down for that, I'd be happy if you could update the PR, breaking the API contract now is pretty out of the question and I don't think we are interested in the PR. |
Ok, I will look into getting this updated and the suggestions incorporated soon™️ |
I support this PR |
Previously additional formatting like brackets around the display name as well as the item information hover event were automatically added when using the
ItemStack#displayName
. In my opinion this did not match the API specification ("Get the formatted display name of the ItemStack", that says nothing about additional characters or hover information) and made it impossible to get the "raw" display name component (which in comparison toItemMeta#displayName
fell back to the default translation if no displayName was set) without any additional data. (Especially the brackets were hard to remove)This changes how the
ItemFactory#displayName
method gets the display name: Instead of directly using theNMS ItemStack#getDisplayName
method (which isn't really correctly named imo) it now directly uses theNMS ItemStack#getHoverName
and applies the italic formatting with the same logic as Vanilla would. We end up with a component that only contains the name as the text without additional characters or hover which Vanilla uses for display purposes in chat e.g. on /give.Old:
New:
The old (wrong) functionality can still easily be achieved with existing API by simply adding the hover event (
ItemStack#asHoverEvent
) to the displayName Component likeitem.displayName().hoverEvent(item)
or if the brackets are desiredComponent.translatable("chat.square_brackets", item.displayName()).hoverEvent(item)
.