Component
Namespace Mc.Scripting.Text · Kind class (sealed)
public sealed class ComponentAn immutable rich text component (vanilla “text component”): text, translatable text, keybind, score or selector content with a style and children. Every method that “changes” a component returns a new one.
Remarks
Section titled “Remarks”Strings convert implicitly to a literal text component (no formatting codes are interpreted, so user input is safe); use Component.Legacy for & codes and Component.Parse for MiniMessage-style tags.
Properties
Section titled “Properties”| Member | Description |
|---|---|
IReadOnlyList<Component> Children { get; } |
The children appended after this component’s own content. |
string Content { get; } |
The literal text of a text component (empty for other kinds). |
bool IsEmpty { get; } |
Whether this is the empty literal component without style or children. |
TextColor TextColour { get; } |
The colour, TextColor.None if inherited. |
static Component Empty { get; } |
The empty component. |
Children
Section titled “Children”public IReadOnlyList<Component> Children { get; }The children appended after this component’s own content.
Content
Section titled “Content”public string Content { get; }The literal text of a text component (empty for other kinds).
IsEmpty
Section titled “IsEmpty”public bool IsEmpty { get; }Whether this is the empty literal component without style or children.
TextColour
Section titled “TextColour”public TextColor TextColour { get; }The colour, TextColor.None if inherited.
public static Component Empty { get; }The empty component.
Methods
Section titled “Methods”| Member | Description |
|---|---|
Component Append(Component child) |
Appends a child component. |
Component Append(string text) |
Appends literal text. |
Component Bold(bool value = true) |
Sets bold. |
Component Color(TextColor color) |
Sets the colour. |
Component Font(string font) |
Sets the font resource key. |
Component Insertion(string text) |
Text inserted into the chat box when the component is shift-clicked. |
Component Italic(bool value = true) |
Sets italic. |
Component Obfuscated(bool value = true) |
Sets obfuscated (random characters). |
Component OnClick(ClickEvent click) |
Sets the click event. |
Component OnHover(HoverEvent hover) |
Sets the hover event. |
Component Strikethrough(bool value = true) |
Sets strikethrough. |
string ToJson() |
Serialises to the vanilla JSON text component form (what the native layer parses). |
string ToPlainText() |
The text of this component and its children without formatting (translatable components show their key). |
override string ToString() |
|
Component Tooltip(Component text) |
Shortcut for a text tooltip. |
Component Underlined(bool value = true) |
Sets underlined. |
static Component FromJson(string json) |
Parses the vanilla JSON form (also a bare JSON string). |
static Component FromJson(Utf8String json) |
Parses the vanilla JSON form from engine memory. |
static Component Join(params Component[] parts) |
Concatenates components into one (an empty parent with the parts as children). |
static Component Join(Component separator, IEnumerable<Component> parts) |
Joins with a separator. |
static Component Keybind(string key) |
A component showing the client’s key binding (e.g. |
static Component Legacy(string text, char prefix = '&') |
Converts text with & colour/format codes (“&aGreen &lbold”) to a component. |
static Component Parse(string markup) |
Parses MiniMessage-style tags: <red>, <#ff8800>, <bold>, <italic>, <underlined>, <strikethrough>, <obfuscated>, <reset>, <click:run_command:/cmd>, <hover:show_text:'text'>, and closing tags </red>. |
static Component Score(string name, string objective) |
A scoreboard score. |
static Component Selector(string selector) |
An entity selector (resolved when sent). |
static Component Text(string text) |
A literal text component. |
static Component Translatable(string key, params Component[] args) |
A translatable component (resolved by the client’s language). |
Append
Section titled “Append”public Component Append(Component child)Appends a child component.
Parameters
| Name | Type | Description |
|---|---|---|
child |
Component |
Returns Component
Append
Section titled “Append”public Component Append(string text)Appends literal text.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns Component
public Component Bold(bool value = true)Sets bold.
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool = true |
Returns Component
public Component Color(TextColor color)Sets the colour.
Parameters
| Name | Type | Description |
|---|---|---|
color |
TextColor |
Returns Component
public Component Font(string font)Sets the font resource key.
Parameters
| Name | Type | Description |
|---|---|---|
font |
string |
Returns Component
Insertion
Section titled “Insertion”public Component Insertion(string text)Text inserted into the chat box when the component is shift-clicked.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns Component
Italic
Section titled “Italic”public Component Italic(bool value = true)Sets italic.
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool = true |
Returns Component
Obfuscated
Section titled “Obfuscated”public Component Obfuscated(bool value = true)Sets obfuscated (random characters).
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool = true |
Returns Component
OnClick
Section titled “OnClick”public Component OnClick(ClickEvent click)Sets the click event.
Parameters
| Name | Type | Description |
|---|---|---|
click |
ClickEvent |
Returns Component
OnHover
Section titled “OnHover”public Component OnHover(HoverEvent hover)Sets the hover event.
Parameters
| Name | Type | Description |
|---|---|---|
hover |
HoverEvent |
Returns Component
Strikethrough
Section titled “Strikethrough”public Component Strikethrough(bool value = true)Sets strikethrough.
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool = true |
Returns Component
ToJson
Section titled “ToJson”public string ToJson()Serialises to the vanilla JSON text component form (what the native layer parses).
Returns string
ToPlainText
Section titled “ToPlainText”public string ToPlainText()The text of this component and its children without formatting (translatable components show their key).
Returns string
ToString
Section titled “ToString”public override string ToString()Returns string
Tooltip
Section titled “Tooltip”public Component Tooltip(Component text)Shortcut for a text tooltip.
Parameters
| Name | Type | Description |
|---|---|---|
text |
Component |
Returns Component
Underlined
Section titled “Underlined”public Component Underlined(bool value = true)Sets underlined.
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool = true |
Returns Component
FromJson
Section titled “FromJson”public static Component FromJson(string json)Parses the vanilla JSON form (also a bare JSON string).
Parameters
| Name | Type | Description |
|---|---|---|
json |
string |
Returns Component
Throws
System.FormatException: The text is not a valid component.
FromJson
Section titled “FromJson”public static Component FromJson(Utf8String json)Parses the vanilla JSON form from engine memory.
Parameters
| Name | Type | Description |
|---|---|---|
json |
Utf8String |
Returns Component
public static Component Join(params Component[] parts)Concatenates components into one (an empty parent with the parts as children).
Parameters
| Name | Type | Description |
|---|---|---|
parts |
params Component[] |
Returns Component
public static Component Join(Component separator, IEnumerable<Component> parts)Joins with a separator.
Parameters
| Name | Type | Description |
|---|---|---|
separator |
Component |
|
parts |
IEnumerable<Component> |
Returns Component
Keybind
Section titled “Keybind”public static Component Keybind(string key)A component showing the client’s key binding (e.g. “key.jump”).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Returns Component
Legacy
Section titled “Legacy”public static Component Legacy(string text, char prefix = '&')Converts text with & colour/format codes (“&aGreen &lbold”) to a component. && is a literal ampersand, &#RRGGBB a custom colour, &r resets.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
|
prefix |
char = '&' |
Returns Component
public static Component Parse(string markup)Parses MiniMessage-style tags: <red>, <#ff8800>, <bold>, <italic>, <underlined>, <strikethrough>, <obfuscated>, <reset>, <click:run_command:/cmd>, <hover:show_text:'text'>, and closing tags </red>. Unknown tags are kept as text. Escape a literal < as \<.
Parameters
| Name | Type | Description |
|---|---|---|
markup |
string |
Returns Component
public static Component Score(string name, string objective)A scoreboard score.
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
Score holder name or selector. |
objective |
string |
Objective name. |
Returns Component
Selector
Section titled “Selector”public static Component Selector(string selector)An entity selector (resolved when sent).
Parameters
| Name | Type | Description |
|---|---|---|
selector |
string |
Returns Component
public static Component Text(string text)A literal text component.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
The text, shown verbatim. |
Returns Component
Translatable
Section titled “Translatable”public static Component Translatable(string key, params Component[] args)A translatable component (resolved by the client’s language).
Parameters
| Name | Type | Description |
|---|---|---|
key |
string |
Translation key, e.g. “chat.type.admin”. |
args |
params Component[] |
Arguments substituted for %s / %1$s. |
Returns Component
Operators
Section titled “Operators”| Member | Description |
|---|---|
static implicit operator Component(string text) |
Literal text converts implicitly. |
operator implicit
Section titled “operator implicit”public static implicit operator Component(string text)Literal text converts implicitly.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns Component
See also
Section titled “See also”ClickEvent · Content · HoverEvent · TextColor · Utf8String