2021-12-24 17:35:12 +01:00
|
|
|
package com.minelittlepony.unicopia.client;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
2022-06-25 00:19:55 +02:00
|
|
|
import net.minecraft.text.*;
|
2021-12-24 17:35:12 +01:00
|
|
|
|
|
|
|
public interface FlowingText {
|
|
|
|
static Stream<Text> wrap(Text text, int maxWidth) {
|
|
|
|
return MinecraftClient.getInstance().textRenderer.getTextHandler().wrapLines(text, maxWidth, Style.EMPTY).stream().map(line -> {
|
2022-06-25 00:19:55 +02:00
|
|
|
MutableText compiled = Text.literal("");
|
2021-12-24 17:35:12 +01:00
|
|
|
line.visit((s, t) -> {
|
2022-06-25 00:19:55 +02:00
|
|
|
compiled.append(Text.literal(t).setStyle(s));
|
2021-12-24 17:35:12 +01:00
|
|
|
return Optional.empty();
|
|
|
|
}, text.getStyle());
|
|
|
|
return compiled;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|