aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java55
1 files changed, 39 insertions, 16 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
index d88ae41..4ad448d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
@@ -1,32 +1,55 @@
package com.anthonyhilyard.iceberg.util;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTextTooltip;
+import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.util.FormattedCharSink;
-public class StringRecomposer implements FormattedCharSink
+public class StringRecomposer
{
- private StringBuilder builder = new StringBuilder();
- private MutableComponent text = new TextComponent("").withStyle(Style.EMPTY);
-
- @Override
- public boolean accept(int index, Style style, int charCode)
+ public static List<FormattedText> recompose(List<ClientTooltipComponent> components)
{
- builder.append(Character.toChars(charCode));
-
- if (!style.equals(text.getStyle()))
+ List<FormattedText> recomposedLines = new ArrayList<>();
+ for (ClientTooltipComponent component : components)
{
- text.append(new TextComponent(builder.toString()).withStyle(style));
- builder.setLength(0);
+ if (component instanceof ClientTextTooltip)
+ {
+ RecomposerSink recomposer = new RecomposerSink();
+ ((ClientTextTooltip)component).text.accept(recomposer);
+ recomposedLines.add(recomposer.getFormattedText());
+ }
}
- return true;
+ return recomposedLines;
}
-
- public FormattedText getFormattedText()
+
+ private static class RecomposerSink implements FormattedCharSink
{
- text.append(new TextComponent(builder.toString()).withStyle(text.getStyle()));
- return text;
+ private StringBuilder builder = new StringBuilder();
+ private MutableComponent text = new TextComponent("").withStyle(Style.EMPTY);
+
+ @Override
+ public boolean accept(int index, Style style, int charCode)
+ {
+ builder.append(Character.toChars(charCode));
+
+ if (!style.equals(text.getStyle()))
+ {
+ text.append(new TextComponent(builder.toString()).withStyle(style));
+ builder.setLength(0);
+ }
+ return true;
+ }
+
+ public FormattedText getFormattedText()
+ {
+ text.append(new TextComponent(builder.toString()).withStyle(text.getStyle()));
+ return text;
+ }
}
}