Interface Style

All Superinterfaces:
Buildable<Style.Builder>, StyleGetter, StyleSetter<Style>

public sealed interface Style extends StyleGetter, StyleSetter<Style>, Buildable<Style.Builder>
A style applies visual effects or extra functionality to Components, such as TextColors, TextDecorations, ClickEvents etc.

Some examples of valid styles:

    Style myStyle = Style.style(ClickEvent.openUrl(url), NamedTextColor.RED, TextDecoration.BOLD);
    Style yourStyle = Style.style(TextColor.color(20, 30, 40), HoverEvent.showText(Component.text("Wow!"));
    Style ourStyle = Style.style().color(NamedTextColor.WHITE).build();
  

A note about fonts: the Key in this context represents the resource location of the font in the same way as Sounds

Since:
4.0.0
  • Field Details

    • DEFAULT_FONT

      static final Key DEFAULT_FONT
      The default font.
      Since:
      4.0.0
      Since Minecraft:
      1.16
  • Method Details

    • empty

      static Style empty()
      Gets an empty style.
      Returns:
      empty style
      Since:
      4.0.0
    • style

      static Style.Builder style()
      Creates a builder.
      Returns:
      a builder
      Since:
      4.0.0
    • style

      static Style style(Consumer<Style.Builder> consumer)
      Creates a style.
      Parameters:
      consumer - the builder consumer
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(@Nullable TextColor color)
      Creates a style with color.
      Parameters:
      color - the style
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(TextDecoration decoration)
      Creates a style with decoration.
      Parameters:
      decoration - the decoration
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(@Nullable TextColor color, TextDecoration... decorations)
      Creates a style with color and decorations.
      Parameters:
      color - the style
      decorations - the decorations
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(@Nullable TextColor color, Set<TextDecoration> decorations)
      Creates a style with color and decorations.
      Parameters:
      color - the style
      decorations - the decorations
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(@Nullable StyleBuilderApplicable... applicables)
      Creates a style with applicables applied.
      Parameters:
      applicables - the applicables
      Returns:
      a style
      Since:
      4.0.0
    • style

      static Style style(Iterable<? extends StyleBuilderApplicable> applicables)
      Creates a style with applicables applied.
      Parameters:
      applicables - the applicables
      Returns:
      a style
      Since:
      4.0.0
    • edit

      default Style edit(Consumer<Style.Builder> consumer)
      Edits this style.

      The old style will be merge into the new style before consumer is called.

      Parameters:
      consumer - the consumer
      Returns:
      a new style
      Since:
      4.0.0
    • edit

      default Style edit(Consumer<Style.Builder> consumer, Style.Merge.Strategy strategy)
      Edits this style.
      Parameters:
      consumer - the consumer
      strategy - the merge strategy
      Returns:
      a new style
      Since:
      4.0.0
    • font

      @Nullable Key font()
      Gets the font.
      Specified by:
      font in interface StyleGetter
      Returns:
      the font
      Since:
      4.0.0
      Since Minecraft:
      1.16
    • font

      Style font(@Nullable Key font)
      Sets the font.
      Specified by:
      font in interface StyleSetter<Style>
      Parameters:
      font - the font
      Returns:
      a style
      Since:
      4.0.0
      Since Minecraft:
      1.16
    • color

      @Nullable TextColor color()
      Gets the color.
      Specified by:
      color in interface StyleGetter
      Returns:
      the color
      Since:
      4.0.0
    • color

      Style color(@Nullable TextColor color)
      Sets the color.
      Specified by:
      color in interface StyleSetter<Style>
      Parameters:
      color - the color
      Returns:
      a style
      Since:
      4.0.0
    • colorIfAbsent

      Style colorIfAbsent(@Nullable TextColor color)
      Sets the color if there isn't one set already.
      Specified by:
      colorIfAbsent in interface StyleSetter<Style>
      Parameters:
      color - the color
      Returns:
      this builder
      Since:
      4.0.0
    • hasDecoration

      default boolean hasDecoration(TextDecoration decoration)
      Tests if this style has a decoration.
      Specified by:
      hasDecoration in interface StyleGetter
      Parameters:
      decoration - the decoration
      Returns:
      true if this style has the decoration, false if this style does not have the decoration
      Since:
      4.0.0
    • decoration

      TextDecoration.State decoration(TextDecoration decoration)
      Gets the state of a decoration on this style.
      Specified by:
      decoration in interface StyleGetter
      Parameters:
      decoration - the decoration
      Returns:
      TextDecoration.State.TRUE if this style has the decoration, TextDecoration.State.FALSE if this style does not have the decoration, and TextDecoration.State.NOT_SET if not set
      Since:
      4.0.0
    • decorate

      default Style decorate(TextDecoration decoration)
      Sets the state of decoration to TextDecoration.State.TRUE on this style.
      Specified by:
      decorate in interface StyleSetter<Style>
      Parameters:
      decoration - the decoration
      Returns:
      a style
      Since:
      4.0.0
    • decoration

      default Style decoration(TextDecoration decoration, boolean flag)
      Sets the state of a decoration on this style.
      Specified by:
      decoration in interface StyleSetter<Style>
      Parameters:
      decoration - the decoration
      flag - true if this style should have the decoration, false if this style should not have the decoration
      Returns:
      a style
      Since:
      4.0.0
    • decoration

      Style decoration(TextDecoration decoration, TextDecoration.State state)
      Sets the value of a decoration on this style.
      Specified by:
      decoration in interface StyleSetter<Style>
      Parameters:
      decoration - the decoration
      state - TextDecoration.State.TRUE if this style should have the decoration, TextDecoration.State.FALSE if this style should not have the decoration, and TextDecoration.State.NOT_SET if the decoration should not have a set value
      Returns:
      a style
      Since:
      4.0.0
    • decorationIfAbsent

      Style decorationIfAbsent(TextDecoration decoration, TextDecoration.State state)
      Sets the state of a decoration on this style to state if the current state of the decoration is TextDecoration.State.NOT_SET.
      Specified by:
      decorationIfAbsent in interface StyleSetter<Style>
      Parameters:
      decoration - the decoration
      state - the state
      Returns:
      a style
      Since:
      4.12.0
    • decorations

      default @Unmodifiable Map<TextDecoration, TextDecoration.State> decorations()
      Gets a map of decorations this style has.
      Specified by:
      decorations in interface StyleGetter
      Returns:
      a map of decorations this style has
      Since:
      4.0.0
    • decorations

      Style decorations(Map<TextDecoration, TextDecoration.State> decorations)
      Sets decorations for this style using the specified decorations map.

      If a given decoration does not have a value explicitly set, the value of that particular decoration is not changed.

      Specified by:
      decorations in interface StyleSetter<Style>
      Parameters:
      decorations - the decorations
      Returns:
      a style
      Since:
      4.0.0
    • clickEvent

      @Nullable ClickEvent<?> clickEvent()
      Gets the click event.
      Specified by:
      clickEvent in interface StyleGetter
      Returns:
      the click event
      Since:
      4.0.0
    • clickEvent

      Style clickEvent(@Nullable ClickEvent<?> event)
      Sets the click event.
      Specified by:
      clickEvent in interface StyleSetter<Style>
      Parameters:
      event - the click event
      Returns:
      a style
      Since:
      4.0.0
    • hoverEvent

      @Nullable HoverEvent<?> hoverEvent()
      Gets the hover event.
      Specified by:
      hoverEvent in interface StyleGetter
      Returns:
      the hover event
      Since:
      4.0.0
    • hoverEvent

      Style hoverEvent(@Nullable HoverEventSource<?> source)
      Sets the hover event.
      Specified by:
      hoverEvent in interface StyleSetter<Style>
      Parameters:
      source - the hover event source
      Returns:
      a style
      Since:
      4.0.0
    • insertion

      @Nullable String insertion()
      Gets the string to be inserted when this style is shift-clicked.
      Specified by:
      insertion in interface StyleGetter
      Returns:
      the insertion string
      Since:
      4.0.0
    • insertion

      Style insertion(@Nullable String insertion)
      Sets the string to be inserted when this style is shift-clicked.
      Specified by:
      insertion in interface StyleSetter<Style>
      Parameters:
      insertion - the insertion string
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that)
      Merges from another style into this style.
      Parameters:
      that - the other style
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Style.Merge.Strategy strategy)
      Merges from another style into this style.
      Parameters:
      that - the other style
      strategy - the merge strategy
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Style.Merge merge)
      Merges from another style into this style.
      Parameters:
      that - the other style
      merge - the part to merge
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Style.Merge.Strategy strategy, Style.Merge merge)
      Merges from another style into this style.
      Parameters:
      that - the other style
      strategy - the merge strategy
      merge - the part to merge
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Style.Merge... merges)
      Merges from another style into this style.
      Parameters:
      that - the other style
      merges - the parts to merge
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Style.Merge.Strategy strategy, Style.Merge... merges)
      Merges from another style into this style.
      Parameters:
      that - the other style
      strategy - the merge strategy
      merges - the parts to merge
      Returns:
      a style
      Since:
      4.0.0
    • merge

      default Style merge(Style that, Set<Style.Merge> merges)
      Merges from another style into this style.
      Parameters:
      that - the other style
      merges - the parts to merge
      Returns:
      a style
      Since:
      4.0.0
    • merge

      Style merge(Style that, Style.Merge.Strategy strategy, Set<Style.Merge> merges)
      Merges from another style into this style.
      Parameters:
      that - the other style
      strategy - the merge strategy
      merges - the parts to merge
      Returns:
      a style
      Since:
      4.0.0
    • unmerge

      Style unmerge(Style that)
      Simplify this style to remove any information that is redundant.
      Parameters:
      that - parent to compare against
      Returns:
      a new, simplified style
      Since:
      4.12.0
    • isEmpty

      boolean isEmpty()
      Tests if this style is empty.
      Returns:
      true if this style is empty, false if this style is not empty
      Since:
      4.0.0
    • toBuilder

      Style.Builder toBuilder()
      Create a builder from this style.
      Specified by:
      toBuilder in interface Buildable<Style.Builder>
      Returns:
      a builder
      Since:
      4.0.0