Skip to content

Class TextColor

Namespace: Void.Minecraft.Components.Text.Colors
Assembly: Void.Minecraft.dll

Represents an RGB color used by a Minecraft text component.

public record TextColor : IEquatable<TextColor>

Inheritance

objectTextColor

Implements

IEquatable<TextColor>

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

TextColor(byte, byte, byte)

Represents an RGB color used by a Minecraft text component.

public TextColor(byte Red, byte Green, byte Blue)

Parameters

Red byte

The red channel.

Green byte

The green channel.

Blue byte

The blue channel.

Properties

Blue

The blue channel.

public byte Blue { get; init; }

Property Value

byte

Green

The green channel.

public byte Green { get; init; }

Property Value

byte

Name

Gets the Minecraft color name, or an uppercase #RRGGBB value for an unnamed color.

public string Name { get; }

Property Value

string

Red

The red channel.

public byte Red { get; init; }

Property Value

byte

Methods

Downsample()

Finds the nearest color in the sixteen-color legacy Minecraft palette.

public TextColor Downsample()

Returns

TextColor

The closest legacy color according to hue, saturation, and brightness distance.

FromString(string)

Parses a Minecraft color name or hexadecimal RGB value.

public static TextColor FromString(string value)

Parameters

value string

A case-insensitive Minecraft color name or a #RRGGBB value.

Returns

TextColor

The parsed color.

Exceptions

ArgumentException

value is not a recognized name or valid hexadecimal color.

ToString()

Returns the canonical color identifier for this value.

public override string ToString()

Returns

string

Remarks

Named Minecraft colors return their registered identifier, such as red or dark_blue. Unmapped colors return a hexadecimal RGB string in #RRGGBB format.

Operators

implicit operator TextColor((byte Red, byte Green, byte Blue))

Creates a color from an RGB tuple.

public static implicit operator TextColor((byte Red, byte Green, byte Blue) color)

Parameters

color (byte Red, byte Green, byte Blue)

The RGB channels.

Returns

TextColor

A color containing the supplied channels.

implicit operator TextColor(Color)

Creates a text color from a drawing color, discarding its alpha channel.

public static implicit operator TextColor(Color color)

Parameters

color Color

The drawing color.

Returns

TextColor

The corresponding RGB text color.

implicit operator TextColor(string)

Parses a named or hexadecimal text color.

public static implicit operator TextColor(string color)

Parameters

color string

A Minecraft color name or #RRGGBB value.

Returns

TextColor

The parsed color.

Exceptions

ArgumentException

color is not a recognized name or valid hexadecimal color.

implicit operator Color(TextColor)

Converts a text color to an opaque drawing color.

public static implicit operator Color(TextColor color)

Parameters

color TextColor

The text color.

Returns

Color

The corresponding drawing color.

implicit operator string(TextColor)

Converts a text color to its canonical identifier.

public static implicit operator string(TextColor color)

Parameters

color TextColor

The text color.

Returns

string

The value of .