From 984f5ca8d63097e4106116e39f4293346ae64a6d Mon Sep 17 00:00:00 2001 From: micle Date: Wed, 14 Jan 2026 00:43:46 +0100 Subject: [PATCH] Improved look of tooltips. Changed colors to improve readability. Implemented helper method for adding indent to components. --- .../item/totem/TotemItem.java | 36 +++++++++---------- .../totem_of_reviving/util/LangAsset.java | 11 ++++-- .../assets/totem_of_reviving/lang/en_us.json | 6 ++-- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/dev/micle/totem_of_reviving/item/totem/TotemItem.java b/src/main/java/dev/micle/totem_of_reviving/item/totem/TotemItem.java index d9018a4..12b2820 100644 --- a/src/main/java/dev/micle/totem_of_reviving/item/totem/TotemItem.java +++ b/src/main/java/dev/micle/totem_of_reviving/item/totem/TotemItem.java @@ -205,51 +205,51 @@ public abstract class TotemItem extends Item { tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_TARGET.getComponent( totemData.getTargetUUID().isPresent() - ? Component.literal(totemData.getTargetName()).withStyle(ChatFormatting.GRAY) + ? Component.literal(totemData.getTargetName()).withStyle(ChatFormatting.WHITE) : LangAsset.GENERAL_NA.getComponent().withStyle(ChatFormatting.RED) - ).withStyle(ChatFormatting.WHITE)); + ).withStyle(ChatFormatting.GRAY)); tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_TARGET_COST.getComponent( Component.literal(String.format("%d", getTargetCost(totemData))).withStyle( getTargetCost(totemData) <= getMaxCharge() - ? ChatFormatting.GRAY + ? ChatFormatting.WHITE : ChatFormatting.RED ) - ).withStyle(ChatFormatting.WHITE)); + ).withStyle(ChatFormatting.GRAY)); tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CHARGES.getComponent( - Component.literal(String.format("%d/%d", totemData.getCharge(), getMaxCharge())).withStyle(ChatFormatting.GRAY) - ).withStyle(ChatFormatting.WHITE)); + Component.literal(String.format("%d / %d", totemData.getCharge(), getMaxCharge())).withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY)); tooltipComponents.add(Component.empty()); if (isChargeCostDynamic()) { tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_DYNAMIC_COST.getComponent( - Component.literal(String.format("%.2f", getConfig().getChargeCostMultiplier())).withStyle(ChatFormatting.GRAY) - ).withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC)); + Component.literal(String.format("%.2f", getConfig().getChargeCostMultiplier())).withStyle(ChatFormatting.WHITE) + ).withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)); } if (getConfig().getCanReviveMoreExpensiveTargets()) { - tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CAN_REVIVE_MORE_EXPENSIVE_TARGETS.getComponent().withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC)); + tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CAN_REVIVE_MORE_EXPENSIVE_TARGETS.getComponent().withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)); } if (getConfig().getCanReviveAcrossDimensions()) { - tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CAN_REVIVE_ACROSS_DIMENSIONS.getComponent().withStyle(ChatFormatting.WHITE, ChatFormatting.ITALIC)); + tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CAN_REVIVE_ACROSS_DIMENSIONS.getComponent().withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)); } tooltipComponents.add(Component.empty()); if (InputConstants.isKeyDown(minecraft.getWindow().getWindow(), minecraft.options.keyShift.getKey().getValue())) { - tooltipComponents.add(LangAsset.TOOLTIP_ADVANCED_TOOLTIP_SHOWN.getComponent().withStyle(ChatFormatting.WHITE, ChatFormatting.UNDERLINE)); + tooltipComponents.add(LangAsset.TOOLTIP_ADVANCED_TOOLTIP_SHOWN.getComponent().withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.UNDERLINE)); - tooltipComponents.add(LangAsset.createKeyText(true, new ChatFormatting[]{ChatFormatting.WHITE}, new ChatFormatting[]{ChatFormatting.GRAY}, minecraft.options.keyUse)); - tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_REVIVE_INSTRUCTION.getComponent().withStyle(ChatFormatting.WHITE)); - tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CHARGE_INSTRUCTION.getComponent().withStyle(ChatFormatting.WHITE)); + tooltipComponents.add(LangAsset.createKeyText(false, new ChatFormatting[]{ChatFormatting.GOLD}, new ChatFormatting[]{ChatFormatting.GOLD, ChatFormatting.ITALIC}, minecraft.options.keyUse)); + tooltipComponents.add(LangAsset.addIndentToComponent(LangAsset.TOOLTIP_TOTEM_REVIVE_INSTRUCTION.getComponent().withStyle(ChatFormatting.GRAY), 1)); + tooltipComponents.add(LangAsset.addIndentToComponent(LangAsset.TOOLTIP_TOTEM_CHARGE_INSTRUCTION.getComponent().withStyle(ChatFormatting.GRAY), 1)); tooltipComponents.add(Component.empty()); - tooltipComponents.add(LangAsset.createKeyText(true, new ChatFormatting[]{ChatFormatting.WHITE}, new ChatFormatting[]{ChatFormatting.GRAY}, minecraft.options.keyShift, minecraft.options.keyUse)); - tooltipComponents.add(LangAsset.TOOLTIP_TOTEM_CHANGE_TARGET_INSTRUCTION.getComponent().withStyle(ChatFormatting.WHITE)); + tooltipComponents.add(LangAsset.createKeyText(false, new ChatFormatting[]{ChatFormatting.GOLD}, new ChatFormatting[]{ChatFormatting.GOLD, ChatFormatting.ITALIC}, minecraft.options.keyShift, minecraft.options.keyUse)); + tooltipComponents.add(LangAsset.addIndentToComponent(LangAsset.TOOLTIP_TOTEM_CHANGE_TARGET_INSTRUCTION.getComponent().withStyle(ChatFormatting.GRAY), 1)); } else { tooltipComponents.add(LangAsset.TOOLTIP_ADVANCED_TOOLTIP_HIDDEN.getComponent( - LangAsset.createKeyText(true, new ChatFormatting[]{ChatFormatting.WHITE}, new ChatFormatting[]{ChatFormatting.GRAY}, minecraft.options.keyShift) - )); + LangAsset.createKeyText(false, new ChatFormatting[]{ChatFormatting.GOLD}, new ChatFormatting[]{ChatFormatting.GOLD, ChatFormatting.ITALIC}, minecraft.options.keyShift) + ).withStyle(ChatFormatting.GRAY)); } super.appendHoverText(stack, context, tooltipComponents, tooltipFlag); diff --git a/src/main/java/dev/micle/totem_of_reviving/util/LangAsset.java b/src/main/java/dev/micle/totem_of_reviving/util/LangAsset.java index eb1e2b8..99f4732 100644 --- a/src/main/java/dev/micle/totem_of_reviving/util/LangAsset.java +++ b/src/main/java/dev/micle/totem_of_reviving/util/LangAsset.java @@ -58,7 +58,14 @@ public enum LangAsset { return Component.translatable(String.format("%s.%s.%s", category, TotemOfReviving.MOD_ID, key), args); } - public static Component createKeyText(boolean isEnclosed, ChatFormatting[] textFormat, ChatFormatting[] keyFormat, KeyMapping...keys) { + public static MutableComponent addIndentToComponent(Component component, int indentLevel) { + List components = new ArrayList<>(); + components.add(Component.literal(" ".repeat(indentLevel))); + components.add(component); + return (MutableComponent) ComponentUtils.formatList(components, Component.empty()); + } + + public static MutableComponent createKeyText(boolean isEnclosed, ChatFormatting[] textFormat, ChatFormatting[] keyFormat, KeyMapping...keys) { List textComponents = new ArrayList<>(); textComponents.add(isEnclosed ? Component.literal("[").withStyle(textFormat) : Component.empty()); for (int i = 0; i < keys.length; i++) { @@ -67,6 +74,6 @@ public enum LangAsset { } textComponents.add(isEnclosed ? Component.literal("]").withStyle(textFormat) : Component.empty()); - return ComponentUtils.formatList(textComponents, Component.empty()); + return (MutableComponent) ComponentUtils.formatList(textComponents, Component.empty()); } } diff --git a/src/main/resources/assets/totem_of_reviving/lang/en_us.json b/src/main/resources/assets/totem_of_reviving/lang/en_us.json index 01a7793..be3a26d 100644 --- a/src/main/resources/assets/totem_of_reviving/lang/en_us.json +++ b/src/main/resources/assets/totem_of_reviving/lang/en_us.json @@ -8,9 +8,9 @@ "item.totem_of_reviving.iron_charge": "Iron reviving charge", "item.totem_of_reviving.diamond_charge": "Diamond reviving charge", "item.totem_of_reviving.netherite_charge": "Netherite reviving charge", - "tooltip.totem_of_reviving.totem_target": "Target -> %s", - "tooltip.totem_of_reviving.totem_target_cost": "Cost -> %s", - "tooltip.totem_of_reviving.totem_charges": "Charges -> %s", + "tooltip.totem_of_reviving.totem_target": "Target: %s", + "tooltip.totem_of_reviving.totem_target_cost": "Cost: %s", + "tooltip.totem_of_reviving.totem_charges": "Charges: %s", "tooltip.totem_of_reviving.totem_dynamic_cost": "Dynamic cost (Multiplier: %s).", "tooltip.totem_of_reviving.totem_can_revive_more_expensive_targets": "Can revive more expensive targets.", "tooltip.totem_of_reviving.totem_can_revive_across_dimensions": "Can revive across dimensions.",