FormattingHelper
com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper
Wraps one of Minecraft's text color or formatting codes.
RESET is neither a color nor a modifier, so isColor() and isModifier() are both false for it.
The color index and RGB value are -1 for modifiers and RESET.
A StyleHelper returns this only for legacy formatting values; arbitrary RGB colors do not have a formatting code.
js
const line = Chat.createTextBuilder().append("a coloured run").withColor(0xc).build();
line.visit(JavaWrapper.methodToJava(function (style, run) {
if (style.hasColor()) {
const formatting = style.getFormatting();
if (formatting !== null) {
Chat.log(`${run}: ${formatting.getName()}, index ${formatting.getColorIndex()}, rgb ${formatting.getColorValue()}`);
}
}
}));Constructors
new FormattingHelper
new FormattingHelper(ChatFormatting base)#Wraps the supplied formatting value without copying or parsing it.
Parameters:
base: raw text color or formatting code to wrap
Methods
getCode
Returns the legacy formatting code character. Prefix it with the section symbol (
§) to form a legacy formatting sequence; color codes are 0–9 and a– f, modifiers are k–o, and RESET is r.Returns: the formatting code character.
getColorIndex
Returns: the legacy color index (
0–15), or -1 for a modifier or RESET.getColorValue
Returns the RGB value for one of the sixteen colors; modifiers and
RESET return -1.Returns: the color value, or
-1 for non-color formats.getName
isColor
Returns:
true for one of the sixteen colors; false for modifiers and RESET.isModifier
Returns:
true for one of the five modifiers; false for colors and RESET.