diff --git a/src/main/java/appeng/integration/modules/igtooltip/parts/P2PStateDataProvider.java b/src/main/java/appeng/integration/modules/igtooltip/parts/P2PStateDataProvider.java index eab2018c8d3..dd61cea4e63 100644 --- a/src/main/java/appeng/integration/modules/igtooltip/parts/P2PStateDataProvider.java +++ b/src/main/java/appeng/integration/modules/igtooltip/parts/P2PStateDataProvider.java @@ -1,5 +1,6 @@ package appeng.integration.modules.igtooltip.parts; +import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -45,10 +46,10 @@ public void buildTooltip(P2PTunnelPart object, TooltipContext context, TooltipBu var freq = serverData.getShort(TAG_P2P_FREQUENCY); // Show the frequency and name of the frequency if it exists - var freqTooltip = Platform.p2p().toHexString(freq); + var freqTooltip = Platform.p2p().toColoredHexString(freq).withStyle(ChatFormatting.BOLD); if (serverData.contains(TAG_P2P_FREQUENCY_NAME, Tag.TAG_STRING)) { var freqName = serverData.getString(TAG_P2P_FREQUENCY_NAME); - freqTooltip = freqName + " (" + freqTooltip + ")"; + freqTooltip = Component.literal(freqName).append(" (").append(freqTooltip).append(")"); } tooltip.addLine(InGameTooltip.P2PFrequency.text(freqTooltip)); diff --git a/src/main/java/appeng/items/tools/MemoryCardItem.java b/src/main/java/appeng/items/tools/MemoryCardItem.java index 7186fa60e69..653fd4dce11 100644 --- a/src/main/java/appeng/items/tools/MemoryCardItem.java +++ b/src/main/java/appeng/items/tools/MemoryCardItem.java @@ -274,7 +274,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List> 4 * (3 - i) & 0xF; + int nibble = getFrequencyNibble(frequency, i); colors[i] = AEColor.values()[nibble]; } @@ -36,6 +39,10 @@ public AEColor[] toColors(short frequency) { return colors; } + private static int getFrequencyNibble(short frequency, int i) { + return frequency >> 4 * (3 - i) & 0xF; + } + public short fromColors(AEColor[] colors) { Preconditions.checkArgument(colors.length == 4); @@ -58,4 +65,20 @@ public String toHexString(short frequency) { return String.format("%04X", frequency); } + private static final String[] HEX_DIGITS = { + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" + }; + + public MutableComponent toColoredHexString(short frequency) { + var parent = Component.empty(); + + for (var i = 0; i < 4; i++) { + var nibble = getFrequencyNibble(frequency, i); + parent.append(Component.literal(HEX_DIGITS[nibble]) + .withColor(AEColor.values()[nibble].whiteVariant)); + } + + return parent; + } + }