|
1 | 1 | package tk.sciwhiz12.concord.util; |
2 | 2 |
|
3 | 3 | import net.minecraft.entity.player.ServerPlayerEntity; |
| 4 | +import net.minecraft.util.text.IFormattableTextComponent; |
| 5 | +import net.minecraft.util.text.ITextComponent; |
4 | 6 | import net.minecraft.util.text.LanguageMap; |
5 | 7 | import net.minecraft.util.text.StringTextComponent; |
| 8 | +import net.minecraft.util.text.Style; |
6 | 9 | import net.minecraft.util.text.TextComponent; |
7 | 10 | import net.minecraft.util.text.TranslationTextComponent; |
| 11 | +import net.minecraft.util.text.event.HoverEvent; |
8 | 12 | import tk.sciwhiz12.concord.ConcordConfig; |
9 | 13 | import tk.sciwhiz12.concord.ModPresenceTracker; |
10 | 14 |
|
@@ -50,14 +54,42 @@ public static TextComponent eagerTranslate(final TranslationTextComponent compon |
50 | 54 | Object obj = oldArgs[i]; |
51 | 55 | if (obj instanceof TranslationTextComponent) { |
52 | 56 | newArgs[i] = eagerTranslate((TranslationTextComponent) obj); |
| 57 | + } else if (obj instanceof IFormattableTextComponent) { |
| 58 | + newArgs[i] = eagerCheckStyle((IFormattableTextComponent) obj); |
53 | 59 | } else { |
54 | 60 | newArgs[i] = oldArgs[i]; |
55 | 61 | } |
56 | 62 | } |
57 | 63 |
|
58 | 64 | TranslationTextComponent result = |
59 | 65 | new TranslationTextComponent(LanguageMap.getInstance().func_230503_a_(component.getKey()), newArgs); |
60 | | - result.mergeStyle(component.getStyle()); |
61 | | - return result; |
| 66 | + result.setStyle(component.getStyle()); |
| 67 | + |
| 68 | + for (ITextComponent sibling : component.getSiblings()) { |
| 69 | + if (sibling instanceof TranslationTextComponent) { |
| 70 | + result.append(eagerTranslate((TranslationTextComponent) sibling)); |
| 71 | + } else if (sibling instanceof IFormattableTextComponent) { |
| 72 | + result.append(eagerCheckStyle((IFormattableTextComponent) sibling)); |
| 73 | + } else { |
| 74 | + result.append(sibling); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + return eagerCheckStyle(result); |
| 79 | + } |
| 80 | + |
| 81 | + public static <Text extends IFormattableTextComponent> Text eagerCheckStyle(Text component) { |
| 82 | + Style style = component.getStyle(); |
| 83 | + HoverEvent hover = style.getHoverEvent(); |
| 84 | + if (hover != null && hover.getAction() == HoverEvent.Action.SHOW_TEXT) { |
| 85 | + ITextComponent hoverText = hover.getParameter(HoverEvent.Action.SHOW_TEXT); |
| 86 | + if (hoverText instanceof TranslationTextComponent) { |
| 87 | + style = style.setHoverEvent( |
| 88 | + new HoverEvent(HoverEvent.Action.SHOW_TEXT, eagerTranslate((TranslationTextComponent) hoverText)) |
| 89 | + ); |
| 90 | + } |
| 91 | + } |
| 92 | + component.setStyle(style); |
| 93 | + return component; |
62 | 94 | } |
63 | 95 | } |
0 commit comments