How do I get the translate key using adventure?
What I want to end up with is
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...
Use anvil and rename it to
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...
Java:
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 examplebefore renaming
Code:
{"color":"white","hoverEvent":{"action":"show_item","contents":{"id":"minecraft:anvil"}},"translate":"chat.square_brackets","with":[{"extra":[{"translate":"block.minecraft.anvil"}],"text":""}]}
after renaming
Code:
{"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":""}]}
- Version Output
- This server is running Paper version git-Paper-307 (MC: 1.19.2) (Implementing API version 1.19.2-R0.1-SNAPSHOT) (Git: 476ef25)
Last edited: