Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add ItemStack#effectiveName

Open masmc05 opened this issue 1 year ago • 1 comments

Adds a new method which returns the name of an itemstack which the player sees in their inventory. Takes into account any data components exactly as vanilla.

Unlike ItemStack#displayName, does not add additional brackets etc

masmc05 avatar Oct 05 '24 01:10 masmc05

Duplicate of #9050

lynxplay avatar Oct 09 '24 21:10 lynxplay

Rebased on 1.21.3

masmc05 avatar Nov 24 '24 13:11 masmc05

Something else that was brought up internally is the whole "display name" naming being outdated/confusing in general now. effectiveName is good for the new method on ItemStack, but we'd like this to go alongside improving ItemStack#displayName docs and replacing ItemMeta displayName methods with customName (since that's what it returns, but other data components can change or be the effective display name). Replace in this case means marking the old as obsolete and linking to the new

kennytv avatar Nov 24 '24 18:11 kennytv

Can I move the ItemStack#displayName from the adventure patch to my patch? It ends up a bit uglier without that

masmc05 avatar Nov 24 '24 18:11 masmc05

Yeah sure

kennytv avatar Nov 24 '24 18:11 kennytv

Applied the deprecation and made the replacement for ItemStack#displayName

masmc05 avatar Nov 24 '24 19:11 masmc05

I'm confused with what's going on in this diff, what kenny asked for was:

  • Improve docs for ItemStack#displayName()
  • Deprecate/obsolete ItemMeta#displayName(Component) and ItemMeta#displayName() in favor of new customName methods (also update the deprecation notice on the legacy methods to point to customName)
  • Add ItemStack#effectiveName() method

jpenilla avatar Nov 26 '24 19:11 jpenilla

ItemMeta#displayName(Component) and ItemMeta#displayName()

Oh, missed that he mentioned ItemMeta and didn't even think of it as this pr didn't touch item meta. Maybe I could just rollback the diff and this pr would just add the new api, and dealing with displayName methods in a separate pr? As personally I disagree with deprecation of a highly used method (I'm sure it's used in almost every plugin) in favor of making an unused by almost every plugin method reflect the mojang naming

masmc05 avatar Nov 26 '24 19:11 masmc05

Not a fan of deprecating the ItemMeta method either. Yes its objectively wrong since two versions, but that thing has been called "display name" in vanilla too for ten years now and just spamming more deprecation will make more people simply ignore them.

I would just deprecate the ItemStack one because its borderline useless. And add a little note to the JD that this works slightly differently in vanilla nowadays.

Malfrador avatar Nov 26 '24 20:11 Malfrador