Class DynamicDescriptionFormatter
java.lang.Object
johnsmith.enchantmentcore.api.tooltip.DynamicDescriptionFormatter
Parses and formats dynamic enchantment descriptions using registered
ValueModifiers and StyleModifiers.
Evaluates nested tag syntax in three sequential passes:
- Pointer interpolation (
<val:key>and<array:key>) viaDynamicDescriptionParser. - Inside-out mathematical value transformation (e.g.,
<percent:<val:key>>,<fixed:2:<div:20:<val:ticks>>>). - Linear stack-based rich text style application (e.g.,
<rgb=#FF5555:content>,<obf:text>,<sga:runes>).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.network.chat.MutableComponentparseAndFormat(String rawDescription, int currentLevel, int maxLevel, Map<String, net.minecraft.world.item.enchantment.LevelBasedValue> args, net.minecraft.network.chat.Style baseStyle, Map<String, StyleModifier> contextStyles) Evaluates a raw description string and constructs a formatted rich textMutableComponent.static voidregisterStyleModifier(String name, StyleModifier modifier) Registers a globalStyleModifieravailable to all dynamic descriptions.static voidregisterValueModifier(String name, ValueModifier modifier) Registers a globalValueModifieravailable to all dynamic descriptions.static List<net.minecraft.network.chat.Component> wrapRich(net.minecraft.network.chat.Component root, int maxChars, int nestingDepth) Wraps a styled rich textComponentinto multiple lines constrained by a maximum character count, preserving individual token styles across line breaks.
-
Constructor Details
-
DynamicDescriptionFormatter
public DynamicDescriptionFormatter()
-
-
Method Details
-
registerValueModifier
Registers a globalValueModifieravailable to all dynamic descriptions. Invalidates the cached regex pattern so it is rebuilt on the next parse call.- Parameters:
name- The command identifier used in description tags (e.g.,"percent").modifier- TheValueModifierimplementation.
-
registerStyleModifier
Registers a globalStyleModifieravailable to all dynamic descriptions.- Parameters:
name- The style command identifier used in description tags (e.g.,"rgb").modifier- TheStyleModifierimplementation.
-
parseAndFormat
public static net.minecraft.network.chat.MutableComponent parseAndFormat(String rawDescription, int currentLevel, int maxLevel, Map<String, net.minecraft.world.item.enchantment.LevelBasedValue> args, net.minecraft.network.chat.Style baseStyle, Map<String, StyleModifier> contextStyles) Evaluates a raw description string and constructs a formatted rich textMutableComponent.Executes pointer resolution, nested mathematical value modifications, and rich style tag applications sequentially.
- Parameters:
rawDescription- The unformatted translation string containing dynamic tag syntax.currentLevel- The active enchantment level for<val:key>pointer evaluation.maxLevel- The maximum enchantment level for<array:key>bracket generation.args- The map of dynamicLevelBasedValuepointers extracted from the enchantment.baseStyle- The foundationalStyleapplied to unstyled root text segments.contextStyles- An optional map of context-specificStyleModifiers that override global style modifiers.- Returns:
- The fully evaluated and styled
MutableComponent.
-
wrapRich
public static List<net.minecraft.network.chat.Component> wrapRich(net.minecraft.network.chat.Component root, int maxChars, int nestingDepth) Wraps a styled rich textComponentinto multiple lines constrained by a maximum character count, preserving individual token styles across line breaks.- Parameters:
root- The source rich textComponentto wrap.maxChars- The maximum character length permitted per line.nestingDepth- The number of leading spaces prepended to each wrapped line.- Returns:
- A list of wrapped line
Components.
-