Skip to content

FormattingHelper ​

com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper

Since1.8.4

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 ​

getCode(): charSince1.8.4#
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 ​

getColorIndex(): intSince1.8.4#
Returns: the legacy color index (0–15), or -1 for a modifier or RESET.

getColorValue ​

getColorValue(): intSince1.8.4#
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 ​

getName(): StringSince1.8.4#
Returns: the lowercase name of this formatting.

isColor ​

isColor(): booleanSince1.8.4#
Returns: true for one of the sixteen colors; false for modifiers and RESET.

isModifier ​

isModifier(): booleanSince1.8.4#
Returns: true for one of the five modifiers; false for colors and RESET.

toString ​

toString(): String#
Returns a diagnostic string containing this formatting's index, color value, name, code, and color and modifier flags.
Returns: diagnostic representation of the wrapped formatting