diff --git a/src/api/java/mcp/mobius/waila/api/component/WrappedComponent.java b/src/api/java/mcp/mobius/waila/api/component/WrappedComponent.java index ede6b1b1..6b2b7713 100644 --- a/src/api/java/mcp/mobius/waila/api/component/WrappedComponent.java +++ b/src/api/java/mcp/mobius/waila/api/component/WrappedComponent.java @@ -1,5 +1,6 @@ package mcp.mobius.waila.api.component; +import java.util.List; import java.util.Objects; import mcp.mobius.waila.api.ITooltipComponent; @@ -9,7 +10,10 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; /** * Component that renders a vanilla {@link Component}. @@ -26,20 +30,34 @@ public WrappedComponent(Component component) { } public final Component component; + private List lines; + private int height; @Override public int getWidth() { - return getFont().width(component); + var font = getFont(); + var split = font.getSplitter().splitLines(component, Integer.MAX_VALUE, Style.EMPTY); + lines = Language.getInstance().getVisualOrder(split); + + var width = lines.stream().mapToInt(font::width).max().orElse(0); + height = font.lineHeight * split.size(); + + return width; } @Override public int getHeight() { - return getFont().lineHeight; + return height; } @Override public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) { - ctx.drawString(getFont(), component, x, y, IApiService.INSTANCE.getFontColor()); + var font = getFont(); + + for (var line : lines) { + ctx.drawString(font, line, x, y, IApiService.INSTANCE.getFontColor()); + y += font.lineHeight; + } } private Font getFont() {