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/Easing.java2
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/StringRecomposer.java32
2 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java
index bc4e39b..2274ce2 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Easing.java
@@ -3,7 +3,7 @@ package com.anthonyhilyard.iceberg.util;
import net.minecraft.network.chat.TextColor;
/**
- * Helper functions for smooth easing/interpolation. If you need linear, use net.minecraft.util.math.MathHelper.lerp instead.
+ * Helper functions for smooth easing/interpolation.
*/
public final class Easing
{
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;
+ }
+}