Skip to content

item displayName problem #878

@twseer67875

Description

@twseer67875

How do I get the translate key using adventure?
What I want to end up with is block.minecraft.anvil
At present, I can only use this stupid method to get it, and when the item is renamed, the Component of the two seems to be different, which makes me puzzled...

String json = GsonComponentSerializer.gson().serialize(item.displayName());
JSONObject jsonObject = new JSONObject(json);
String key = jsonObject       
        .getJSONArray("with") 
        .getJSONObject(0)
        .getJSONArray("extra")
        .getJSONObject(0)    
        .getString("translate");

Use anvil and rename it to test as an example
before renaming

{"color":"white","hoverEvent":{"action":"show_item","contents":{"id":"minecraft:anvil"}},"translate":"chat.square_brackets","with":[{"extra":[{"translate":"block.minecraft.anvil"}],"text":""}]}

after renaming

{"color":"white","hoverEvent":{"action":"show_item","contents":{"id":"minecraft:anvil","tag":"{display:{Name:\u0027{\"text\":\"test\"}\u0027}}"}},"translate":"chat.square_brackets","with":[{"italic":true,"extra":[{"text":"test"}],"text":""}]}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions