ITextComponent
Link to itextcomponent
The ITextComponent interface is the format Minecraft uses to send and display rich text to players.
导入相关包
Link to 导入相关包
It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import.
import crafttweaker.text.ITextComponent;
Creating an ITextComponent
Link to creating-an-itextcomponent
You can cast an IFormattedText as ITextComponent (using the AS
keyword, or the asTextComponent()
method) or use these static methods below.
ZenScript Copyimport crafttweaker.text.ITextComponent;
ITextComponent.fromString(String s);
ITextComponent.fromTranslation(String translationKey);
ITextComponent.fromTranslation(String translationKey, Object... args);
ITextComponent.fromData(IData data);
Note: the argument of fromData
method is raw JSON text format.
ZenGetters and ZenSetters
Link to zengetters-and-zensetters
ZenGetter | ZenSetter | 类型 | 描述 |
---|---|---|---|
ZenGetter 样式 | ZenSetter 样式 | 类型 IStyle | 描述 |
ZenGetter unformattedComponentText | ZenSetter | 类型 string | 描述 Gets the raw content of this component (but not its sibling components), without any formatting codes. |
ZenGetter unformattedText | ZenSetter | 类型 string | 描述 Gets the text of this component and all sibling components, without any formatting codes. |
ZenGetter formattedText | ZenSetter | 类型 string | 描述 Gets the text of this component and all sibling components, with formatting codes added for rendering. |
ZenGetter siblings | ZenSetter | 类型 List<ITextComponent> | 描述 Gets the sibling components of this one. |
ZenMethod
Link to zenmethod
ITextComponent createCopy();
Creates a copy of this component. Almost a deep copy, except the style is shallow-copied.
ZenOperators
Link to zenoperators
You can add or concatenate two ITextComponent together using the respecting Operators: + ~