Interface TextColor

All Superinterfaces:
Comparable<TextColor>, ComponentBuilderApplicable, RGBLike, StyleBuilderApplicable, TextFormat
All Known Implementing Classes:
NamedTextColor

public non-sealed interface TextColor extends Comparable<TextColor>, RGBLike, StyleBuilderApplicable, TextFormat
A color which may be applied to a Style.

The full range of hexadecimal colors are only supported in Minecraft: Java Edition 1.16 and above. On older versions, platforms may downsample these to NamedTextColors.

This color does not include any alpha channel information.

Since:
4.0.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The hex character.
    static final String
    The hex character, in String format.
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    Gets the color, as a hex string.
    default @Range(from=0L,to=255L) int
    Get the blue component of the text colour.
    static TextColor
    color(@Range(from=0L,to=255L) int r, @Range(from=0L,to=255L) int g, @Range(from=0L,to=255L) int b)
    Create a new text colour with the red, green, and blue components individually.
    static TextColor
    color(float r, float g, float b)
    Create a new color with the individual components as floats.
    static TextColor
    color(int value)
    Creates a new text colour.
    static TextColor
    Creates a new text color, converting the provided HSVLike to the RGB color space.
    static TextColor
    Creates a new text colour.
    default int
     
    static @Nullable TextColor
    Create a color from a CSS hex string (#rrggbb or #rgb).
    static @Nullable TextColor
    Create a new color from a hex string.
    default @Range(from=0L,to=255L) int
    Get the green component of the text colour.
    static TextColor
    lerp(float t, RGBLike a, RGBLike b)
    Linearly interpolates between a and b by t.
    static <C extends TextColor>
    C
    nearestColorTo(List<C> values, TextColor any)
    Find the colour nearest to the provided colour.
    default @Range(from=0L,to=255L) int
    red()
    Get the red component of the text colour.
    default void
    Applies to style.
    int
    The color, as an RGB value packed into an int.

    Methods inherited from interface RGBLike

    asHSV

    Methods inherited from interface StyleBuilderApplicable

    componentBuilderApply
  • Field Details

    • HEX_CHARACTER

      static final char HEX_CHARACTER
      The hex character.
      Since:
      4.14.0
      See Also:
    • HEX_PREFIX

      static final String HEX_PREFIX
      The hex character, in String format.
      Since:
      4.14.0
      See Also:
  • Method Details

    • color

      static TextColor color(int value)
      Creates a new text colour.
      Parameters:
      value - the rgb value
      Returns:
      a new text colour
      Since:
      4.0.0
    • color

      static TextColor color(RGBLike rgb)
      Creates a new text colour.
      Parameters:
      rgb - the rgb value
      Returns:
      a new text colour
      Since:
      4.0.0
    • color

      static TextColor color(HSVLike hsv)
      Creates a new text color, converting the provided HSVLike to the RGB color space.
      Parameters:
      hsv - the hsv value
      Returns:
      a new text color
      Since:
      4.6.0
      See Also:
    • color

      static TextColor color(@Range(from=0L,to=255L) int r, @Range(from=0L,to=255L) int g, @Range(from=0L,to=255L) int b)
      Create a new text colour with the red, green, and blue components individually.
      Parameters:
      r - red, as a value from 0 to 255
      g - green, as a value from 0 to 255
      b - blue, as a value from 0 to 255
      Returns:
      a new text colour
      Since:
      4.0.0
    • color

      static TextColor color(float r, float g, float b)
      Create a new color with the individual components as floats.
      Parameters:
      r - red, from [0, 1]
      g - green, within [0, 1]
      b - blue, within [0, 1]
      Returns:
      a new text colour
      Since:
      4.0.0
    • fromHexString

      static @Nullable TextColor fromHexString(String string)
      Create a new color from a hex string.
      Parameters:
      string - the hex string
      Returns:
      a new text colour
      Since:
      4.0.0
    • fromCSSHexString

      static @Nullable TextColor fromCSSHexString(String string)
      Create a color from a CSS hex string (#rrggbb or #rgb).
      Parameters:
      string - the hex string
      Returns:
      a new text colour
      Since:
      4.0.0
    • value

      int value()
      The color, as an RGB value packed into an int.
      Returns:
      the value
      Since:
      4.0.0
    • asHexString

      default String asHexString()
      Gets the color, as a hex string.
      Returns:
      a hex string
      Since:
      4.0.0
    • red

      default @Range(from=0L,to=255L) int red()
      Get the red component of the text colour.
      Specified by:
      red in interface RGBLike
      Returns:
      the red component, in the range [0x0, 0xff]
      Since:
      4.0.0
    • green

      default @Range(from=0L,to=255L) int green()
      Get the green component of the text colour.
      Specified by:
      green in interface RGBLike
      Returns:
      the green component, in the range [0x0, 0xff]
      Since:
      4.0.0
    • blue

      default @Range(from=0L,to=255L) int blue()
      Get the blue component of the text colour.
      Specified by:
      blue in interface RGBLike
      Returns:
      the blue component, in the range [0x0, 0xff]
      Since:
      4.0.0
    • lerp

      static TextColor lerp(float t, RGBLike a, RGBLike b)
      Linearly interpolates between a and b by t.

      This returns a color blended between color a, at t=0.0, and color b, at t=1.0.

      Parameters:
      t - the interpolation value, between 0.0 and 1.0 (both inclusive)
      a - the lower bound (t=0.0)
      b - the upper bound (t=1.0)
      Returns:
      the interpolated value, a color between the two input colors a and b
      Since:
      4.8.0
    • nearestColorTo

      static <C extends TextColor> C nearestColorTo(List<C> values, TextColor any)
      Find the colour nearest to the provided colour.
      Type Parameters:
      C - the color type
      Parameters:
      values - the colours for matching
      any - colour to match
      Returns:
      nearest named colour. will always return a value
      Since:
      4.14.0
    • styleApply

      default void styleApply(Style.Builder style)
      Description copied from interface: StyleBuilderApplicable
      Applies to style.
      Specified by:
      styleApply in interface StyleBuilderApplicable
      Parameters:
      style - the style builder
    • compareTo

      default int compareTo(TextColor that)
      Specified by:
      compareTo in interface Comparable<TextColor>