Skip to content

Commit

Permalink
Fix GT Format Codes in Translatables
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Dec 15, 2024
1 parent a848480 commit 951f9f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/main/groovy-tests/jeiTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/nomiceu/nomilabs/util/LabsTranslate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}

Expand Down

0 comments on commit 951f9f2

Please sign in to comment.