Skip to content
Lenni0451 edited this page Oct 27, 2023 · 4 revisions

Components

The following text components are implemented:

  • StringComponent
  • TranslationComponent
  • ScoreComponent
  • SelectorComponent
  • KeybindComponent
  • NbtComponent
    • BlockNbtComponent
    • EntityNbtComponent
    • StorageNbtComponent

The NbtComponent has 3 subtypes because of different component arguments.

Formatting

Text components can have styling which is implemented in the Style class. Styles can have the following properties:

  • color
  • obfuscated
  • bold
  • strikethrough
  • underlined
  • italic
  • clickEvent
  • hoverEvent
  • insertion
  • font

Events

Click events

Click events have the following click actions:

  • open url
  • open file
  • run command
  • twitch user info
  • suggest command
  • change page
  • copy to clipboard

Hover events

Hover events have the following hover actions:

  • show text
  • show achievement
  • show item
  • show entity

Hover elements have different content depending on the action which are implemented in subclasses:

  • EntityHoverEvent
  • ItemHoverEvent
  • TextHoverEvent

Serializing/Deserializing Texts

All default serializers are implemented in the TextComponentSerializer class:

  • V1_6
  • V1_7
  • V1_8
  • V1_9
  • V1_12
  • V1_14
  • V1_15
  • V1_16
  • V1_17
  • V1_18
  • V1_19_4
  • V1_20_3

Serializing

To serialize a text component you can use the following methods:

  • serialize(textComponent)
  • serializeJson(textComponent)

Deserializing

To deserialize a text component you can use the following methods:

  • deserialize(string)
  • deserialize(jsonElement)
  • deserializeParser(string)
  • deserializeReader(string)
  • deserializeLenientReader(string)
  • deserializeReader(string, lenient)

All methods can throw a JsonParseException if the json is not a valid text component.

Text Codecs

In minecraft 1.20.3+ text component serialization is done using codecs.
To support this change the new serializers are in the TextComponentCodec class now. The new codec serializers have a TextComponentSerializer associated with them.
If you want to serializer/deserialize text components to/from nbt you need to use the new codec class.

Methods for deserialization:

  • deserializeNbt(string)
  • deserializeNbtTree(iNbtTag)
  • deserialize(iNbtTag)

Methods for serialization:

  • serializeNbt(textComponent)
  • serializeNbtString(textComponent)
Clone this wiki locally