aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2021-10-18 22:42:15 -0700
committerAnthony Hilyard <anthony.hilyard@gmail.com>2021-10-18 22:42:15 -0700
commite5e86bedca56374e40fe14fea76a16295cc1673e (patch)
treef952d16ad7aff7d10e1ea5be59a79f4a751ebbb7 /src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
parent2077b6b7c9b63d329bd095a8632f40136a3ba352 (diff)
downloadIceberg-e5e86bedca56374e40fe14fea76a16295cc1673e.tar.gz
Iceberg-e5e86bedca56374e40fe14fea76a16295cc1673e.tar.bz2
Iceberg-e5e86bedca56374e40fe14fea76a16295cc1673e.zip
Readded RenderTooltipEvent.PostText, since it was removed in a recent
version of Forge.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
new file mode 100644
index 0000000..d88ae41
--- /dev/null
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java
@@ -0,0 +1,32 @@
+package com.anthonyhilyard.iceberg.util;
+
+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
+{
+ 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;
+ }
+}