Interface Text

All Superinterfaces:
com.mojang.brigadier.Message, StringVisitable
All Known Implementing Classes:
MutableText

public interface Text extends com.mojang.brigadier.Message, StringVisitable
A text. Can be converted to and from JSON format.

Each text has a tree structure, embodying all its siblings. To iterate contents in the text and all its siblings, call visit methods.

This interface does not expose mutation operations. For mutation, refer to MutableText.

See Also:
Mappings:
Namespace Name
named net/minecraft/text/Text
intermediary net/minecraft/class_2561
official xp
  • Method Details

    • getStyle

      Style getStyle()
      Returns the style of this text.
      Mappings:
      Namespace Name Mixin selector
      named getStyle Lnet/minecraft/text/Text;getStyle()Lnet/minecraft/text/Style;
      intermediary method_10866 Lnet/minecraft/class_2561;method_10866()Lnet/minecraft/class_2583;
      official a Lxp;a()Lym;
    • getContent

      TextContent getContent()
      Returns the content of the text.
      Returns:
      the content of the text
      Mappings:
      Namespace Name Mixin selector
      named getContent Lnet/minecraft/text/Text;getContent()Lnet/minecraft/text/TextContent;
      intermediary method_10851 Lnet/minecraft/class_2561;method_10851()Lnet/minecraft/class_7417;
      official b Lxp;b()Lxq;
    • getString

      default String getString()
      Specified by:
      getString in interface com.mojang.brigadier.Message
      Specified by:
      getString in interface StringVisitable
    • asTruncatedString

      default String asTruncatedString(int length)
      Returns the full string representation of this text, truncated beyond the supplied length.
      Parameters:
      length - the max length allowed for the string representation of the text
      Mappings:
      Namespace Name Mixin selector
      named asTruncatedString Lnet/minecraft/text/Text;asTruncatedString(I)Ljava/lang/String;
      intermediary method_10858 Lnet/minecraft/class_2561;method_10858(I)Ljava/lang/String;
      official a Lxp;a(I)Ljava/lang/String;
    • getSiblings

      List<Text> getSiblings()
      Returns the siblings of this text.
      Mappings:
      Namespace Name Mixin selector
      named getSiblings Lnet/minecraft/text/Text;getSiblings()Ljava/util/List;
      intermediary method_10855 Lnet/minecraft/class_2561;method_10855()Ljava/util/List;
      official c Lxp;c()Ljava/util/List;
    • getLiteralString

      @Nullable default @Nullable String getLiteralString()
      Returns the string of the literal text, or null if this text is not a literal.

      A literal text is an unstyled PlainTextContent without any siblings. Such texts are serialized as a string instead of an object.

      Returns:
      the string of the literal text, or null if this text is not a literal
      Mappings:
      Namespace Name Mixin selector
      named getLiteralString Lnet/minecraft/text/Text;getLiteralString()Ljava/lang/String;
      intermediary method_54160 Lnet/minecraft/class_2561;method_54160()Ljava/lang/String;
      official d Lxp;d()Ljava/lang/String;
    • copyContentOnly

      default MutableText copyContentOnly()
      Copies the text's content, excluding the styles or siblings.
      Mappings:
      Namespace Name Mixin selector
      named copyContentOnly Lnet/minecraft/text/Text;copyContentOnly()Lnet/minecraft/text/MutableText;
      intermediary method_27662 Lnet/minecraft/class_2561;method_27662()Lnet/minecraft/class_5250;
      official e Lxp;e()Lyd;
    • copy

      default MutableText copy()
      Copies the text's content, the style, and the siblings.

      A shallow copy is made for the siblings.

      Mappings:
      Namespace Name Mixin selector
      named copy Lnet/minecraft/text/Text;copy()Lnet/minecraft/text/MutableText;
      intermediary method_27661 Lnet/minecraft/class_2561;method_27661()Lnet/minecraft/class_5250;
      official f Lxp;f()Lyd;
    • asOrderedText

      OrderedText asOrderedText()
      Mappings:
      Namespace Name Mixin selector
      named asOrderedText Lnet/minecraft/text/Text;asOrderedText()Lnet/minecraft/text/OrderedText;
      intermediary method_30937 Lnet/minecraft/class_2561;method_30937()Lnet/minecraft/class_5481;
      official g Lxp;g()Layl;
    • visit

      default <T> Optional<T> visit(StringVisitable.StyledVisitor<T> styledVisitor, Style style)
      Supplies this visitable's literal content and contextual style to the visitor.
      Specified by:
      visit in interface StringVisitable
      Parameters:
      styledVisitor - the visitor
      style - the contextual style
      Returns:
      Optional.empty() if the visit finished, or a terminating result from the visitor
      Mappings:
      Namespace Name Mixin selector
      named visit Lnet/minecraft/text/StringVisitable;visit(Lnet/minecraft/text/StringVisitable$StyledVisitor;Lnet/minecraft/text/Style;)Ljava/util/Optional;
      intermediary method_27658 Lnet/minecraft/class_5348;method_27658(Lnet/minecraft/class_5348$class_5246;Lnet/minecraft/class_2583;)Ljava/util/Optional;
      official a Lxu;a(Lxu$b;Lym;)Ljava/util/Optional;
    • visit

      default <T> Optional<T> visit(StringVisitable.Visitor<T> visitor)
      Supplies this visitable's literal content to the visitor.
      Specified by:
      visit in interface StringVisitable
      Parameters:
      visitor - the visitor
      Returns:
      Optional.empty() if the visit finished, or a terminating result from the visitor
      Mappings:
      Namespace Name Mixin selector
      named visit Lnet/minecraft/text/StringVisitable;visit(Lnet/minecraft/text/StringVisitable$Visitor;)Ljava/util/Optional;
      intermediary method_27657 Lnet/minecraft/class_5348;method_27657(Lnet/minecraft/class_5348$class_5245;)Ljava/util/Optional;
      official a Lxu;a(Lxu$a;)Ljava/util/Optional;
    • withoutStyle

      default List<Text> withoutStyle()
      Mappings:
      Namespace Name Mixin selector
      named withoutStyle Lnet/minecraft/text/Text;withoutStyle()Ljava/util/List;
      intermediary method_44746 Lnet/minecraft/class_2561;method_44746()Ljava/util/List;
      official h Lxp;h()Ljava/util/List;
    • getWithStyle

      default List<Text> getWithStyle(Style style)
      Mappings:
      Namespace Name Mixin selector
      named getWithStyle Lnet/minecraft/text/Text;getWithStyle(Lnet/minecraft/text/Style;)Ljava/util/List;
      intermediary method_36136 Lnet/minecraft/class_2561;method_36136(Lnet/minecraft/class_2583;)Ljava/util/List;
      official a Lxp;a(Lym;)Ljava/util/List;
    • contains

      default boolean contains(Text text)
      Returns whether the text contains text, without considering styles.
      Returns:
      whether the text contains text, without considering styles
      Mappings:
      Namespace Name Mixin selector
      named contains Lnet/minecraft/text/Text;contains(Lnet/minecraft/text/Text;)Z
      intermediary method_44745 Lnet/minecraft/class_2561;method_44745(Lnet/minecraft/class_2561;)Z
      official a Lxp;a(Lxp;)Z
    • of

      static Text of(@Nullable @Nullable String string)
      Creates a literal text with the given string as content.
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Ljava/lang/String;)Lnet/minecraft/text/Text;
      intermediary method_30163 Lnet/minecraft/class_2561;method_30163(Ljava/lang/String;)Lnet/minecraft/class_2561;
      official a Lxp;a(Ljava/lang/String;)Lxp;
    • literal

      static MutableText literal(String string)
      Mappings:
      Namespace Name Mixin selector
      named literal Lnet/minecraft/text/Text;literal(Ljava/lang/String;)Lnet/minecraft/text/MutableText;
      intermediary method_43470 Lnet/minecraft/class_2561;method_43470(Ljava/lang/String;)Lnet/minecraft/class_5250;
      official b Lxp;b(Ljava/lang/String;)Lyd;
    • translatable

      static MutableText translatable(String key)
      Mappings:
      Namespace Name Mixin selector
      named translatable Lnet/minecraft/text/Text;translatable(Ljava/lang/String;)Lnet/minecraft/text/MutableText;
      intermediary method_43471 Lnet/minecraft/class_2561;method_43471(Ljava/lang/String;)Lnet/minecraft/class_5250;
      official c Lxp;c(Ljava/lang/String;)Lyd;
    • translatable

      static MutableText translatable(String key, Object[] args)
      Returns a translatable text with arguments.

      The arguments passed must be either numbers, booleans, strings, or another Text. Use stringifiedTranslatable(java.lang.String, java.lang.Object[]) to construct texts with other objects as arguments. Alternatively, convert them using static methods here like of(Identifier).

      Returns:
      a translatable text with arguments
      Mappings:
      Namespace Name Mixin selector
      named translatable Lnet/minecraft/text/Text;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/text/MutableText;
      intermediary method_43469 Lnet/minecraft/class_2561;method_43469(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/class_5250;
      official a Lxp;a(Ljava/lang/String;[Ljava/lang/Object;)Lyd;
    • stringifiedTranslatable

      static MutableText stringifiedTranslatable(String key, Object[] args)
      Returns a translatable text with arguments.

      Arguments that are not numbers, booleans, strings, or another Text are converted to strings using String.valueOf(Object).

      Returns:
      a translatable text with arguments
      Mappings:
      Namespace Name Mixin selector
      named stringifiedTranslatable Lnet/minecraft/text/Text;stringifiedTranslatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/text/MutableText;
      intermediary method_54159 Lnet/minecraft/class_2561;method_54159(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/class_5250;
      official b Lxp;b(Ljava/lang/String;[Ljava/lang/Object;)Lyd;
    • translatableWithFallback

      static MutableText translatableWithFallback(String key, @Nullable @Nullable String fallback)
      Mappings:
      Namespace Name Mixin selector
      named translatableWithFallback Lnet/minecraft/text/Text;translatableWithFallback(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/text/MutableText;
      intermediary method_48321 Lnet/minecraft/class_2561;method_48321(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_5250;
      official a Lxp;a(Ljava/lang/String;Ljava/lang/String;)Lyd;
    • translatableWithFallback

      static MutableText translatableWithFallback(String key, @Nullable @Nullable String fallback, Object[] args)
      Mappings:
      Namespace Name Mixin selector
      named translatableWithFallback Lnet/minecraft/text/Text;translatableWithFallback(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/text/MutableText;
      intermediary method_48322 Lnet/minecraft/class_2561;method_48322(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/class_5250;
      official a Lxp;a(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Lyd;
    • empty

      static MutableText empty()
      Mappings:
      Namespace Name Mixin selector
      named empty Lnet/minecraft/text/Text;empty()Lnet/minecraft/text/MutableText;
      intermediary method_43473 Lnet/minecraft/class_2561;method_43473()Lnet/minecraft/class_5250;
      official i Lxp;i()Lyd;
    • keybind

      static MutableText keybind(String string)
      Mappings:
      Namespace Name Mixin selector
      named keybind Lnet/minecraft/text/Text;keybind(Ljava/lang/String;)Lnet/minecraft/text/MutableText;
      intermediary method_43472 Lnet/minecraft/class_2561;method_43472(Ljava/lang/String;)Lnet/minecraft/class_5250;
      official d Lxp;d(Ljava/lang/String;)Lyd;
    • nbt

      static MutableText nbt(String rawPath, boolean interpret, Optional<Text> separator, NbtDataSource dataSource)
      Mappings:
      Namespace Name Mixin selector
      named nbt Lnet/minecraft/text/Text;nbt(Ljava/lang/String;ZLjava/util/Optional;Lnet/minecraft/text/NbtDataSource;)Lnet/minecraft/text/MutableText;
      intermediary method_43468 Lnet/minecraft/class_2561;method_43468(Ljava/lang/String;ZLjava/util/Optional;Lnet/minecraft/class_7419;)Lnet/minecraft/class_5250;
      official a Lxp;a(Ljava/lang/String;ZLjava/util/Optional;Lyr;)Lyd;
    • score

      static MutableText score(String name, String objective)
      Mappings:
      Namespace Name Mixin selector
      named score Lnet/minecraft/text/Text;score(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/text/MutableText;
      intermediary method_43466 Lnet/minecraft/class_2561;method_43466(Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/class_5250;
      official b Lxp;b(Ljava/lang/String;Ljava/lang/String;)Lyd;
    • selector

      static MutableText selector(String pattern, Optional<Text> separator)
      Mappings:
      Namespace Name Mixin selector
      named selector Lnet/minecraft/text/Text;selector(Ljava/lang/String;Ljava/util/Optional;)Lnet/minecraft/text/MutableText;
      intermediary method_43467 Lnet/minecraft/class_2561;method_43467(Ljava/lang/String;Ljava/util/Optional;)Lnet/minecraft/class_5250;
      official a Lxp;a(Ljava/lang/String;Ljava/util/Optional;)Lyd;
    • of

      static Text of(Date date)
      Returns a literal text representing date.
      Returns:
      a literal text representing date
      Implementation Note:
      The date is converted to a string using Date.toString(). Notably, it does not localize the date format.
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Ljava/util/Date;)Lnet/minecraft/text/Text;
      intermediary method_54157 Lnet/minecraft/class_2561;method_54157(Ljava/util/Date;)Lnet/minecraft/class_2561;
      official a Lxp;a(Ljava/util/Date;)Lxp;
    • of

      static Text of(com.mojang.brigadier.Message message)
      Returns a text with message.

      If a text instance is passed, this method returns message itself; otherwise this creates a new literal text with the message content.

      Returns:
      a text with message
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Lcom/mojang/brigadier/Message;)Lnet/minecraft/text/Text;
      intermediary method_54155 Lnet/minecraft/class_2561;method_54155(Lcom/mojang/brigadier/Message;)Lnet/minecraft/class_2561;
      official a Lxp;a(Lcom/mojang/brigadier/Message;)Lxp;
    • of

      static Text of(UUID uuid)
      Returns a text representing uuid.

      The UUID is converted to a string like 12345678-90AB-CDEF-1234-567890ABCDEF.

      Returns:
      a text representing uuid
      See Also:
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Ljava/util/UUID;)Lnet/minecraft/text/Text;
      intermediary method_54158 Lnet/minecraft/class_2561;method_54158(Ljava/util/UUID;)Lnet/minecraft/class_2561;
      official a Lxp;a(Ljava/util/UUID;)Lxp;
    • of

      static Text of(Identifier id)
      Returns a text representing id.

      The returned text has the format namespace:path. Namespace is always included.

      Returns:
      a text representing id
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Lnet/minecraft/util/Identifier;)Lnet/minecraft/text/Text;
      intermediary method_54154 Lnet/minecraft/class_2561;method_54154(Lnet/minecraft/class_2960;)Lnet/minecraft/class_2561;
      official a Lxp;a(Lalf;)Lxp;
    • of

      static Text of(ChunkPos pos)
      Returns a text representing chunk pos.

      The returned text has the format [X, Z].

      Returns:
      a text representing chunk pos
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/text/Text;of(Lnet/minecraft/util/math/ChunkPos;)Lnet/minecraft/text/Text;
      intermediary method_54156 Lnet/minecraft/class_2561;method_54156(Lnet/minecraft/class_1923;)Lnet/minecraft/class_2561;
      official a Lxp;a(Ldbh;)Lxp;