diff --git a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java index a0a0d6f60..66aab2272 100644 --- a/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java +++ b/src/main/java/com/simibubi/create/foundation/item/ItemDescription.java @@ -35,7 +35,7 @@ public class ItemDescription { public static final ItemDescription MISSING = new ItemDescription(null); public static ITextComponent trim = - new StringTextComponent(WHITE + "" + STRIKETHROUGH + " "); + new StringTextComponent(" ").formatted(WHITE, STRIKETHROUGH); public enum Palette { @@ -82,7 +82,7 @@ public class ItemDescription { SpeedLevel minimumRequiredSpeedLevel = isEngine ? SpeedLevel.NONE : ((IRotate) block).getMinimumRequiredSpeedLevel(); boolean hasSpeedRequirement = minimumRequiredSpeedLevel != SpeedLevel.NONE; - ResourceLocation id = ((Block) block).getRegistryName(); + ResourceLocation id = block.getRegistryName(); Map> impacts = config.stressValues.getImpacts(); Map> capacities = config.stressValues.getCapacities(); boolean hasStressImpact = impacts.containsKey(id) && impacts.get(id) @@ -178,9 +178,9 @@ public class ItemDescription { boolean hasControls = !linesOnCtrl.isEmpty(); if (hasDescription || hasControls) { - String[] holdKey = Lang.translate("tooltip.holdKey", "$").getUnformattedComponentText() + String[] holdKey = TooltipHelper.getUnformattedDeepText(Lang.translate("tooltip.holdKey", "$")) .split("\\$"); - String[] holdKeyOrKey = Lang.translate("tooltip.holdKeyOrKey", "$", "$").getUnformattedComponentText() + String[] holdKeyOrKey = TooltipHelper.getUnformattedDeepText(Lang.translate("tooltip.holdKeyOrKey", "$", "$")) .split("\\$"); ITextComponent keyShift = Lang.translate("tooltip.keyShift"); ITextComponent keyCtrl = Lang.translate("tooltip.keyCtrl"); @@ -193,30 +193,23 @@ public class ItemDescription { continue; } - StringBuilder tabBuilder = new StringBuilder(); - tabBuilder.append(DARK_GRAY); + IFormattableTextComponent tabBuilder = StringTextComponent.EMPTY.copy(); if (hasDescription && hasControls) { tabBuilder.append(holdKeyOrKey[0]); - tabBuilder.append(shift ? palette.hColor : palette.color); - tabBuilder.append(keyShift); - tabBuilder.append(DARK_GRAY); + tabBuilder.append(keyShift.copy().formatted(shift ? palette.hColor : palette.color)); tabBuilder.append(holdKeyOrKey[1]); - tabBuilder.append(ctrl ? palette.hColor : palette.color); - tabBuilder.append(keyCtrl); - tabBuilder.append(DARK_GRAY); + tabBuilder.append(keyCtrl.copy().formatted(ctrl ? palette.hColor : palette.color)); tabBuilder.append(holdKeyOrKey[2]); } else { tabBuilder.append(holdKey[0]); - tabBuilder.append((hasDescription ? shift : ctrl) ? palette.hColor : palette.color); - tabBuilder.append(hasDescription ? keyShift : keyCtrl); - tabBuilder.append(DARK_GRAY); + tabBuilder.append((hasDescription ? keyShift : keyCtrl).copy().formatted((hasDescription ? shift : ctrl) ? palette.hColor : palette.color)); tabBuilder.append(holdKey[1]); } - - list.add(0, new StringTextComponent(tabBuilder.toString())); + tabBuilder.formatted(DARK_GRAY); + list.add(0, tabBuilder); if (shift || ctrl) - list.add(1, new StringTextComponent("")); + list.add(1, StringTextComponent.EMPTY); } } 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 2ab57c5e4..8260778b7 100644 --- a/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java +++ b/src/main/java/com/simibubi/create/foundation/item/TooltipHelper.java @@ -104,7 +104,7 @@ public class TooltipHelper { lineStart.formatted(defaultColor); List lines = new ArrayList<>(); - String rawText = c.getUnformattedComponentText(); + String rawText = getUnformattedDeepText(c); String[] words = rawText.split(" "); String word; IFormattableTextComponent currentLine = lineStart.copy(); @@ -251,4 +251,13 @@ public class TooltipHelper { return l.get(); } + public static String getUnformattedDeepText(ITextComponent component) { + StringBuilder b = new StringBuilder(); + b.append(component.getString()); + component.getSiblings().forEach(c -> { + b.append(getUnformattedDeepText(c)); + }); + return b.toString(); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/item/WipScription.java b/src/main/java/com/simibubi/create/foundation/item/WipScription.java index 21e68056a..91fd8270b 100644 --- a/src/main/java/com/simibubi/create/foundation/item/WipScription.java +++ b/src/main/java/com/simibubi/create/foundation/item/WipScription.java @@ -30,14 +30,13 @@ public class WipScription extends ItemDescription { @Override public List addInformation(List tooltip) { - tooltip.set(0, new StringTextComponent(decorateName(tooltip.get(0).getString()))); + tooltip.set(0, decorateName(tooltip.get(0))); tooltip.addAll(getLines()); return tooltip; } - public static String decorateName(String name) { - return TextFormatting.GRAY + "" + TextFormatting.STRIKETHROUGH + name + TextFormatting.GOLD + " " - + Lang.translate("tooltip.wip"); + public static ITextComponent decorateName(ITextComponent name) { + return StringTextComponent.EMPTY.copy().append(name.copy().formatted(TextFormatting.GRAY, TextFormatting.STRIKETHROUGH)).append(" ").append(Lang.translate("tooltip.wip").formatted(TextFormatting.GOLD)); } }