Wrap text in the gemstone's tooltips

This commit is contained in:
Sollace 2021-12-24 18:35:12 +02:00
parent 3d2a50655b
commit 301c68218e
2 changed files with 24 additions and 1 deletions

View file

@ -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<Text> 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;
});
}
}

View file

@ -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.CustomisedSpellType;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; 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.PlayerCharmTracker;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
@ -66,7 +67,7 @@ public class GemstoneItem extends Item {
line = line.formatted(Formatting.OBFUSCATED); line = line.formatted(Formatting.OBFUSCATED);
} }
lines.add(line); lines.addAll(FlowingText.wrap(line, 180).toList());
} }
} }