Question How get text from displayName()

GreenLink

New member
Feb 16, 2022
3
0
1
Is there now an easy way to get text from displayName() , like (Deprecated) getDisplayName()
How do I get the text correctly now?
 

_Iuri

New member
Jan 16, 2022
18
3
3
Yeah, sure... you can use:
Code:
((TextComponent)getDisplayName()).content()

The use of Adventure for text is very annoying :/
 

rymiel

New member
Feb 16, 2022
2
0
1
Components represent rich text used by Minecraft itself. Typically the answer to "how to get the text" depends on what you need it for, there are very few legitimate uses to actually get the plain text, as components can hold things that cannot be easily represented by simple text
Yeah, sure... you can use:
Code:
((TextComponent)getDisplayName()).content()

The use of Adventure for text is very annoying :/
This is very prone to breaking and ignores everything about the structure of components
 

GreenLink

New member
Feb 16, 2022
3
0
1
Components represent rich text used by Minecraft itself. Typically the answer to "how to get the text" depends on what you need it for, there are very few legitimate uses to actually get the plain text, as components can hold things that cannot be easily represented by simple text

This is very prone to breaking and ignores everything about the structure of components
I need the text of the item name without other formatting
 

broccoli

New member
Jan 4, 2022
2
1
0
1
I need the text of the item name without other formatting
Why? You shouldn’t be storing data in an items name or lore, unless you have a really good reason not to. You should store any information in the itemstacks persistent data container.
 

Machine Maker

Paper Developer
Staff member
Dec 17, 2021
51
3
9
8
California
Yeah, sure... you can use:
Code:
((TextComponent)getDisplayName()).content()

The use of Adventure for text is very annoying :/
This is a very not good way to get the text. What happens if I set the display name of an itemstack to a translatable component, or some other component type? Casting it to TextComponent isn't going to work then. Like others have said, there are very few legitimate reasons to want the plain text content of a component. Otherwise, you shouldn't try to convert Minecraft's tree-like text component structure to a 2 dimensional string.
 

MCMDEV

New member
Mar 13, 2022
3
1
3
Java:
PlainTextComponentSerializer.plainText().serialize()
should work for most cases and is certainly cleaner than ripping out the content of a TextComponent.
 
  • Like
Reactions: _Iuri

_Iuri

New member
Jan 16, 2022
18
3
3
Java:
PlainTextComponentSerializer.plainText().serialize()
should work for most cases and is certainly cleaner than ripping out the content of a TextComponent.
Yeah, this is the correct what to get the Component's plain text