Class Style

java.lang.Object
net.minecraft.text.Style

public class Style
extends Object
The style of a Text, representing cosmetic attributes. It includes font, formatting, click/hover events (actions), color, etc.

A style is immutable.

See Also:
Text
  • Field Details

  • Constructor Details

  • Method Details

    • getColor

      @Nullable public TextColor getColor()
      Returns the color of this style.
    • isBold

      public boolean isBold()
      Returns whether the style has bold formatting.
      See Also:
      Formatting.BOLD
    • isItalic

      public boolean isItalic()
      Returns whether the style has italic formatting.
      See Also:
      Formatting.ITALIC
    • isStrikethrough

      public boolean isStrikethrough()
      Returns whether the style has strikethrough formatting.
      See Also:
      Formatting.STRIKETHROUGH
    • isUnderlined

      public boolean isUnderlined()
      Returns whether the style has underline formatting.
      See Also:
      Formatting.UNDERLINE
    • isObfuscated

      public boolean isObfuscated()
      Returns whether the style has obfuscated formatting.
      See Also:
      Formatting.OBFUSCATED
    • isEmpty

      public boolean isEmpty()
      Returns if this is the empty style.
      See Also:
      EMPTY
    • getClickEvent

      @Nullable public ClickEvent getClickEvent()
      Returns the click event of this style.
    • getHoverEvent

      @Nullable public HoverEvent getHoverEvent()
      Returns the hover event of this style.
    • getInsertion

      @Nullable public String getInsertion()
      Returns the insertion text of the style.

      An insertion is inserted when a piece of text clicked while shift key is down in the chat HUD.

    • getFont

      public Identifier getFont()
      Returns the font of this style.
    • withColor

      public Style withColor​(@Nullable TextColor color)
      Returns a new style with the color provided and all other attributes of this style.
      Parameters:
      color - the new color
    • withColor

      public Style withColor​(@Nullable Formatting color)
      Returns a new style with the color provided and all other attributes of this style.
      Parameters:
      color - the new color
    • withBold

      public Style withBold​(@Nullable Boolean bold)
      Returns a new style with the bold attribute provided and all other attributes of this style.
      Parameters:
      bold - the new bold property
    • withItalic

      public Style withItalic​(@Nullable Boolean italic)
      Returns a new style with the italic attribute provided and all other attributes of this style.
      Parameters:
      italic - the new italic property
    • withUnderline

      @Environment(CLIENT) public Style withUnderline​(@Nullable Boolean underline)
      Returns a new style with the underline attribute provided and all other attributes of this style.
    • withClickEvent

      public Style withClickEvent​(@Nullable ClickEvent clickEvent)
      Returns a new style with the click event provided and all other attributes of this style.
      Parameters:
      clickEvent - the new click event
    • withHoverEvent

      public Style withHoverEvent​(@Nullable HoverEvent hoverEvent)
      Returns a new style with the hover event provided and all other attributes of this style.
      Parameters:
      hoverEvent - the new hover event
    • withInsertion

      public Style withInsertion​(@Nullable String insertion)
      Returns a new style with the insertion provided and all other attributes of this style.
      Parameters:
      insertion - the new insertion string
    • withFont

      @Environment(CLIENT) public Style withFont​(@Nullable Identifier font)
      Returns a new style with the font provided and all other attributes of this style.
      Parameters:
      font - the new font
    • withFormatting

      public Style withFormatting​(Formatting formatting)
      Returns a new style with the formatting provided and all other attributes of this style.
      Parameters:
      formatting - the new formatting
    • withExclusiveFormatting

      @Environment(CLIENT) public Style withExclusiveFormatting​(Formatting formatting)
      Returns a new style with the formatting provided and some applicable attributes of this style.

      When a color formatting is passed for formatting, the other formattings, including bold, italic, strikethrough, underlined, and obfuscated, are all removed.

      Parameters:
      formatting - the new formatting
    • withFormatting

      public Style withFormatting​(Formatting[] formattings)
      Returns a new style with the formattings provided and all other attributes of this style.
      Parameters:
      formattings - an array of new formattings
    • withParent

      public Style withParent​(Style parent)
      Returns a new style with the undefined attributes of this style filled by the parent style.
      Parameters:
      parent - the parent style
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object