TextHelper
com.jsmacrosce.jsmacros.client.api.helper.TextHelper
Wraps a Minecraft text component, which can contain text with different styles and click or hover behavior.
visit(com.jsmacrosce.jsmacros.core.MethodWrapper) visits each text run with its StyleHelper; getString() returns the flattened text without styling.
Create helpers from strings, translation keys, or component JSON with the corresponding Chat.createTextHelperFrom... methods. replaceFromString(String) replaces this helper's component; it does not update text already displayed elsewhere.
js
// Read the component's flattened text
const line = Chat.createTextHelperFromString("some styled line");
Chat.log(`flattened: ${line.getString()}`);
// Inspect each formatted run
line.visit(JavaWrapper.methodToJava(function (style, run) {
if (style.bold()) {
Chat.log(`bold run: ${run}`);
}
}));
// Build translated text for display
Chat.actionbar(Chat.createTextHelperFromTranslationKey("block.minecraft.stone"));Fields
STRIP_FORMATTING_PATTERN
Matches a section sign followed by a legacy formatting code (
0-9, A-F, K-O, or R), case-insensitively. Used by getStringStripFormatting() and withoutFormatting().Methods
getJson
getString
getStringStripFormatting
getWidth
Returns: the rendered width of the component in client font units
toString
visit
Visits each text run with its style and text, then returns this helper.
Parameters:
visitor: callback receiving a StyleHelper and the run's text
Returns: self for chaining
withoutFormatting
Returns: a new helper containing the flattened text with legacy section-sign formatting codes removed
wrap
static wrap(Component t): TextHelper#Wraps a component in a helper, retaining the supplied component as-is.
Parameters:
t: the component to wrap, ornull
Returns: a new helper retaining
t, or null when t is null