From 951f9f28e6de837e862f8bd7e7234df3285a9a49 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Sun, 15 Dec 2024 22:11:28 +1100 Subject: [PATCH] Fix GT Format Codes in Translatables --- src/main/groovy-tests/jeiTests.groovy | 4 +++- .../nomiceu/nomilabs/util/LabsTranslate.java | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/groovy-tests/jeiTests.groovy b/src/main/groovy-tests/jeiTests.groovy index 90415ca6..f9919a99 100644 --- a/src/main/groovy-tests/jeiTests.groovy +++ b/src/main/groovy-tests/jeiTests.groovy @@ -86,7 +86,9 @@ crafting.shapedBuilder() * Recipe Input Tooltips. These are tooltips that appear on CRAFTING TABLE recipes, on a specific registry name and index. */ -// Similar outside of builder +// Outside of builder +addRecipeInputTooltip('gregtech:block_decompress_aluminium', 4, + translatableLiteral("This is consumed!!!").addFormat(TooltipHelper.BLINKING_CYAN)) // In a crafting shaped/shapeless builder crafting.shapelessBuilder() diff --git a/src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java b/src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java index b3f7b217..7ebe62c6 100644 --- a/src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java +++ b/src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java @@ -5,6 +5,8 @@ import java.util.IllegalFormatException; import java.util.List; +import javax.annotation.Nullable; + import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.translation.I18n; @@ -68,7 +70,7 @@ public static String format(String str, TooltipHelper.GTFormatCode... formats) { } public static String format(String str, Format... formats) { - return String.join("", Arrays.stream(formats).map((format) -> format.format).toArray(String[]::new)) + str + + return String.join("", Arrays.stream(formats).map(Format::getFormat).toArray(String[]::new)) + str + TextFormatting.RESET; } @@ -90,18 +92,28 @@ public static String topTranslate(String key) { public static class Format { - public final String format; + private final String format; + + // Stored as instance so colors can be updated per call + @Nullable + private final TooltipHelper.GTFormatCode gtCode; - private Format(String format) { + private Format(String format, @Nullable TooltipHelper.GTFormatCode gtCode) { this.format = format; + this.gtCode = gtCode; } public static Format of(TextFormatting format) { - return new Format(format.toString()); + return new Format(format.toString(), null); } public static Format of(TooltipHelper.GTFormatCode format) { - return new Format(format.toString()); + return new Format(format.toString(), format); + } + + public String getFormat() { + if (gtCode != null) return gtCode.toString(); + return format; } }