From 5d0674067f73139095a7ae3b84e73d8f69155a20 Mon Sep 17 00:00:00 2001 From: Snownee Date: Thu, 14 Jan 2021 11:52:48 +0800 Subject: [PATCH] Fix TooltipHelper formatting --- .../create/foundation/item/TooltipHelper.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java index 80b0c4923..988981e0c 100644 --- a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java @@ -170,7 +170,7 @@ public class TooltipHelper { StringBuilder currentLine = new StringBuilder(); int width = 0; for (String word : words) { - int newWidth = font.getStringWidth(word); + int newWidth = font.getStringWidth(word.replaceAll("_", "")); if (width + newWidth > maxWidthPerLine) { if (width > 0) { String line = currentLine.toString(); @@ -190,24 +190,22 @@ public class TooltipHelper { } // Format - IFormattableTextComponent lineStart = StringTextComponent.EMPTY.copy(); - for (int i = 0; i < indent; i++) - lineStart.append(" "); + IFormattableTextComponent lineStart = new StringTextComponent(Strings.repeat(" ", indent)); lineStart.formatted(defaultColor); List formattedLines = new ArrayList<>(lines.size()); Couple f = Couple.create(highlightColor, defaultColor); - + + boolean currentlyHighlighted = false; for (String string : lines) { - boolean currentlyHighlighted = false; IFormattableTextComponent currentComponent = lineStart.copy(); String[] split = string.split("_"); for (String part : split) { currentComponent.append(new StringTextComponent(part).formatted(f.get(currentlyHighlighted))); - if (split.length != 1) - currentlyHighlighted = !currentlyHighlighted; + currentlyHighlighted = !currentlyHighlighted; } formattedLines.add(currentComponent); + currentlyHighlighted = !currentlyHighlighted; }