diff --git a/src/main/java/com/minelittlepony/unicopia/client/FlowingText.java b/src/main/java/com/minelittlepony/unicopia/client/FlowingText.java new file mode 100644 index 00000000..25461b80 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/client/FlowingText.java @@ -0,0 +1,22 @@ +package com.minelittlepony.unicopia.client; + +import java.util.Optional; +import java.util.stream.Stream; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; + +public interface FlowingText { + static Stream wrap(Text text, int maxWidth) { + return MinecraftClient.getInstance().textRenderer.getTextHandler().wrapLines(text, maxWidth, Style.EMPTY).stream().map(line -> { + LiteralText compiled = new LiteralText(""); + line.visit((s, t) -> { + compiled.append(new LiteralText(t).setStyle(s)); + return Optional.empty(); + }, text.getStyle()); + return compiled; + }); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java index 2cd7ac98..efc68e93 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java @@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.client.FlowingText; import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker; import com.minelittlepony.unicopia.entity.player.Pony; @@ -66,7 +67,7 @@ public class GemstoneItem extends Item { line = line.formatted(Formatting.OBFUSCATED); } - lines.add(line); + lines.addAll(FlowingText.wrap(line, 180).toList()); } }