Package net.minecraft.text
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Style.Serializer
A JSON serializer forStyle
. -
Field Summary
Fields Modifier and Type Field Description private Boolean
bold
private ClickEvent
clickEvent
private TextColor
color
static Identifier
DEFAULT_FONT_ID
The identifier for the default font of a style.static Style
EMPTY
An empty style.private Identifier
font
private HoverEvent
hoverEvent
private String
insertion
private Boolean
italic
private Boolean
obfuscated
private Boolean
strikethrough
private Boolean
underlined
-
Constructor Summary
Constructors Modifier Constructor Description private
Style(TextColor color, Boolean bold, Boolean italic, Boolean underlined, Boolean strikethrough, Boolean obfuscated, ClickEvent clickEvent, HoverEvent hoverEvent, String insertion, Identifier font)
-
Method Summary
Modifier and Type Method Description boolean
equals(Object obj)
ClickEvent
getClickEvent()
Returns the click event of this style.TextColor
getColor()
Returns the color of this style.Identifier
getFont()
Returns the font of this style.HoverEvent
getHoverEvent()
Returns the hover event of this style.String
getInsertion()
Returns the insertion text of the style.int
hashCode()
boolean
isBold()
Returns whether the style has bold formatting.boolean
isEmpty()
Returns if this is the empty style.boolean
isItalic()
Returns whether the style has italic formatting.boolean
isObfuscated()
Returns whether the style has obfuscated formatting.boolean
isStrikethrough()
Returns whether the style has strikethrough formatting.boolean
isUnderlined()
Returns whether the style has underline formatting.String
toString()
Style
withBold(Boolean bold)
Returns a new style with the bold attribute provided and all other attributes of this style.Style
withClickEvent(ClickEvent clickEvent)
Returns a new style with the click event provided and all other attributes of this style.Style
withColor(TextColor color)
Returns a new style with the color provided and all other attributes of this style.Style
withColor(Formatting color)
Returns a new style with the color provided and all other attributes of this style.Style
withExclusiveFormatting(Formatting formatting)
Returns a new style with the formatting provided and some applicable attributes of this style.Style
withFont(Identifier font)
Returns a new style with the font provided and all other attributes of this style.Style
withFormatting(Formatting formatting)
Returns a new style with the formatting provided and all other attributes of this style.Style
withFormatting(Formatting[] formattings)
Returns a new style with the formattings provided and all other attributes of this style.Style
withHoverEvent(HoverEvent hoverEvent)
Returns a new style with the hover event provided and all other attributes of this style.Style
withInsertion(String insertion)
Returns a new style with the insertion provided and all other attributes of this style.Style
withItalic(Boolean italic)
Returns a new style with the italic attribute provided and all other attributes of this style.Style
withParent(Style parent)
Returns a new style with the undefined attributes of this style filled by theparent
style.Style
withUnderline(Boolean underline)
Returns a new style with the underline attribute provided and all other attributes of this style.
-
Field Details
-
EMPTY
An empty style. -
DEFAULT_FONT_ID
The identifier for the default font of a style. -
color
-
bold
-
italic
-
underlined
-
strikethrough
-
obfuscated
-
clickEvent
-
hoverEvent
-
insertion
-
font
-
-
Constructor Details
-
Style
private Style(@Nullable TextColor color, @Nullable Boolean bold, @Nullable Boolean italic, @Nullable Boolean underlined, @Nullable Boolean strikethrough, @Nullable Boolean obfuscated, @Nullable ClickEvent clickEvent, @Nullable HoverEvent hoverEvent, @Nullable String insertion, @Nullable Identifier font)
-
-
Method Details
-
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
Returns the click event of this style. -
getHoverEvent
Returns the hover event of this style. -
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
Returns the font of this style. -
withColor
Returns a new style with the color provided and all other attributes of this style.- Parameters:
color
- the new color
-
withColor
Returns a new style with the color provided and all other attributes of this style.- Parameters:
color
- the new color
-
withBold
Returns a new style with the bold attribute provided and all other attributes of this style.- Parameters:
bold
- the new bold property
-
withItalic
Returns a new style with the italic attribute provided and all other attributes of this style.- Parameters:
italic
- the new italic property
-
withUnderline
Returns a new style with the underline attribute provided and all other attributes of this style. -
withClickEvent
Returns a new style with the click event provided and all other attributes of this style.- Parameters:
clickEvent
- the new click event
-
withHoverEvent
Returns a new style with the hover event provided and all other attributes of this style.- Parameters:
hoverEvent
- the new hover event
-
withInsertion
Returns a new style with the insertion provided and all other attributes of this style.- Parameters:
insertion
- the new insertion string
-
withFont
Returns a new style with the font provided and all other attributes of this style.- Parameters:
font
- the new font
-
withFormatting
Returns a new style with the formatting provided and all other attributes of this style.- Parameters:
formatting
- the new formatting
-
withExclusiveFormatting
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
Returns a new style with the formattings provided and all other attributes of this style.- Parameters:
formattings
- an array of new formattings
-
withParent
Returns a new style with the undefined attributes of this style filled by theparent
style.- Parameters:
parent
- the parent style
-
toString
-
equals
-
hashCode
public int hashCode()
-