Skip to content

Tooltip Formatting

JohnSmith474 edited this page Sep 21, 2026 · 1 revision

Vanilla Minecraft rigidly enforces how enchantment tooltips are displayed: Enchantment Name + Roman Numeral Level. When building complex magic overhauls or RPG-style progression systems, this default formatting often falls short.

EnchantmentCore provides the TooltipFormatterRegistry to allow developers to completely intercept and rewrite how specific enchantments (or groups of enchantments) are displayed on items.

The Formatter Interface

To manipulate a tooltip, implement the EnchantmentTooltipFormatter interface.

import johnsmith.enchantmentcore.api.tooltip.EnchantmentTooltipFormatter;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.enchantment.Enchantment;
import java.util.List;
import java.util.Optional;

public class MyCustomFormatter implements EnchantmentTooltipFormatter {
    
    @Override
    public Optional<List<Component>> format(Holder<Enchantment> enchantment, int level) {
        // Return Optional.empty() if this formatter should ignore the current enchantment.
        if (!enchantment.is(MyModTags.REQUIRES_CUSTOM_TOOLTIP)) {
            return Optional.empty();
        }

        // Return your custom formatted components.
        return Optional.of(List.of(
            Component.literal("★ " + enchantment.value().description().getString() + " ★").withStyle(ChatFormatting.GOLD),
            Component.literal("  Power Level: " + level).withStyle(ChatFormatting.GRAY)
        ));
    }

    @Override
    public int getPriority() {
        return 100; // Higher values execute before lower values
    }
}

Priority and Execution

The TooltipFormatterRegistry maintains a prioritized list of all registered formatters. When the client generates an item's tooltip, it iterates through this list descending by priority.

The first formatter to return a populated Optional<List<Component>> successfully claims the tooltip, and subsequent formatters are skipped. If all formatters return Optional.empty(), the system falls back to the standard vanilla rendering string.

Registration

Register your formatter during your mod's initialization phase:

import johnsmith.enchantmentcore.api.tooltip.TooltipFormatterRegistry;

public class MyMod {
    public static void init() {
        TooltipFormatterRegistry.register(new MyCustomFormatter());
    }
}

Utility Classes

EnchantmentCore provides two utility classes specifically designed to assist with building complex lore descriptions in your tooltips.

TooltipLineWrapper

Automatically splits long Component strings into multiple lines based on a strict character limit, preserving chat styling and optional indentation depths.

// Wraps text to 30 characters per line, indented by 1 depth unit ("  ").
List<Component> loreLines = TooltipLineWrapper.wrap(longDescriptionComponent, 30, 1);

RomanNumeralConverter

Provides fast translation between standard integers and classical Roman numerals. Supports values from 1 to 3999.

String numeral = RomanNumeralConverter.toRoman(15); // Returns "XV"
int value = RomanNumeralConverter.parse("IV");      // Returns 4

Clone this wiki locally