Package net.kyori.adventure.text.format
Interface TextColor
-
- All Superinterfaces:
java.lang.Comparable<TextColor>,ComponentBuilderApplicable,net.kyori.examination.Examinable,RGBLike,StyleBuilderApplicable,TextFormat
- All Known Implementing Classes:
NamedTextColor
public interface TextColor extends java.lang.Comparable<TextColor>, net.kyori.examination.Examinable, RGBLike, StyleBuilderApplicable, TextFormat
A color which may be applied to aStyle.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:
NamedTextColor
-
-
Field Summary
Fields Modifier and Type Field Description static charHEX_CHARACTERThe hex character.static java.lang.StringHEX_PREFIXThe hex character, inStringformat.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default @NotNull java.lang.StringasHexString()Gets the color, as a hex string.default @org.jetbrains.annotations.Range(from=0L, to=255L) intblue()Get the blue component of the text colour.static @NotNull TextColorcolor(@org.jetbrains.annotations.Range(from=0L, to=255L) int r, @org.jetbrains.annotations.Range(from=0L, to=255L) int g, @org.jetbrains.annotations.Range(from=0L, to=255L) int b)Create a new text colour with the red, green, and blue components individually.static @NotNull TextColorcolor(float r, float g, float b)Create a new color with the individual components as floats.static @NotNull TextColorcolor(int value)Creates a new text colour.static @NotNull TextColorcolor(@NotNull HSVLike hsv)Creates a new text color, converting the providedHSVLiketo the RGB color space.static @NotNull TextColorcolor(@NotNull RGBLike rgb)Creates a new text colour.default intcompareTo(TextColor that)default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty>examinableProperties()static @Nullable TextColorfromCSSHexString(@NotNull java.lang.String string)Create a color from a CSS hex string (#rrggbbor#rgb).static @Nullable TextColorfromHexString(@NotNull java.lang.String string)Create a new color from a hex string.default @org.jetbrains.annotations.Range(from=0L, to=255L) intgreen()Get the green component of the text colour.static @NotNull TextColorlerp(float t, @NotNull RGBLike a, @NotNull RGBLike b)Linearly interpolates betweenaandbbyt.static <C extends TextColor>
CnearestColorTo(@NotNull java.util.List<C> values, @NotNull TextColor any)Find the colour nearest to the provided colour.default @org.jetbrains.annotations.Range(from=0L, to=255L) intred()Get the red component of the text colour.default voidstyleApply(@NotNull Style.Builder style)Applies tostyle.intvalue()The color, as an RGB value packed into an int.-
Methods inherited from interface net.kyori.adventure.text.format.StyleBuilderApplicable
componentBuilderApply
-
-
-
-
Field Detail
-
HEX_CHARACTER
static final char HEX_CHARACTER
The hex character.- Since:
- 4.14.0
- See Also:
- Constant Field Values
-
HEX_PREFIX
static final java.lang.String HEX_PREFIX
The hex character, inStringformat.- Since:
- 4.14.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
color
@NotNull static @NotNull TextColor color(int value)
Creates a new text colour.- Parameters:
value- the rgb value- Returns:
- a new text colour
- Since:
- 4.0.0
-
color
@NotNull static @NotNull TextColor color(@NotNull @NotNull RGBLike rgb)
Creates a new text colour.- Parameters:
rgb- the rgb value- Returns:
- a new text colour
- Since:
- 4.0.0
-
color
@NotNull static @NotNull TextColor color(@NotNull @NotNull HSVLike hsv)
Creates a new text color, converting the providedHSVLiketo the RGB color space.- Parameters:
hsv- the hsv value- Returns:
- a new text color
- Since:
- 4.6.0
- See Also:
- https://en.wikipedia.org/wiki/HSL_and_HSV
-
color
@NotNull static @NotNull TextColor color(@org.jetbrains.annotations.Range(from=0L, to=255L) int r, @org.jetbrains.annotations.Range(from=0L, to=255L) int g, @org.jetbrains.annotations.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 255g- green, as a value from 0 to 255b- blue, as a value from 0 to 255- Returns:
- a new text colour
- Since:
- 4.0.0
-
color
@NotNull static @NotNull 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
@Nullable static @Nullable TextColor fromHexString(@NotNull @NotNull java.lang.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
@Nullable static @Nullable TextColor fromCSSHexString(@NotNull @NotNull java.lang.String string)
Create a color from a CSS hex string (#rrggbbor#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
@NotNull default @NotNull java.lang.String asHexString()
Gets the color, as a hex string.- Returns:
- a hex string
- Since:
- 4.0.0
-
red
default @org.jetbrains.annotations.Range(from=0L, to=255L) int red()
Get the red component of the text colour.
-
green
default @org.jetbrains.annotations.Range(from=0L, to=255L) int green()
Get the green component of the text colour.
-
blue
default @org.jetbrains.annotations.Range(from=0L, to=255L) int blue()
Get the blue component of the text colour.
-
lerp
@NotNull static @NotNull TextColor lerp(float t, @NotNull @NotNull RGBLike a, @NotNull @NotNull RGBLike b)
Linearly interpolates betweenaandbbyt.This returns a color blended between color
a, att=0.0, and colorb, att=1.0.- Parameters:
t- the interpolation value, between0.0and1.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
aandb - Since:
- 4.8.0
-
nearestColorTo
@NotNull static <C extends TextColor> C nearestColorTo(@NotNull @NotNull java.util.List<C> values, @NotNull @NotNull TextColor any)
Find the colour nearest to the provided colour.- Type Parameters:
C- the color type- Parameters:
values- the colours for matchingany- colour to match- Returns:
- nearest named colour. will always return a value
- Since:
- 4.14.0
-
styleApply
default void styleApply(@NotNull Style.Builder style)
Description copied from interface:StyleBuilderApplicableApplies tostyle.- Specified by:
styleApplyin interfaceStyleBuilderApplicable- Parameters:
style- the style builder
-
compareTo
default int compareTo(TextColor that)
- Specified by:
compareToin interfacejava.lang.Comparable<TextColor>
-
examinableProperties
@NotNull default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()
- Specified by:
examinablePropertiesin interfacenet.kyori.examination.Examinable
-
-