Style.java

net.minecraft.network.chat.Style

信息

  • 全限定名:net.minecraft.network.chat.Style
  • 类型:public final class
  • 包:net.minecraft.network.chat
  • 源码路径:src/main/java/net/minecraft/network/chat/Style.java
  • 起始行号:L15
  • 职责:

    TODO

字段/常量

  • EMPTY

    • 类型: Style
    • 修饰符: public static final
    • 源码定位: L16
    • 说明:

      TODO

  • NO_SHADOW

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L17
    • 说明:

      TODO

  • color

    • 类型: TextColor
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • shadowColor

    • 类型: Integer
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • bold

    • 类型: Boolean
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • italic

    • 类型: Boolean
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • underlined

    • 类型: Boolean
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • strikethrough

    • 类型: Boolean
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • obfuscated

    • 类型: Boolean
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • clickEvent

    • 类型: ClickEvent
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • hoverEvent

    • 类型: HoverEvent
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • insertion

    • 类型: String
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • font

    • 类型: FontDescription
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.network.chat.Style.Collector

    • 类型: class
    • 修饰符: package-private
    • 源码定位: L527
    • 说明:

      TODO

  • net.minecraft.network.chat.Style.Serializer

    • 类型: class
    • 修饰符: public static
    • 源码定位: L617
    • 说明:

      TODO

构造器

private Style(TextColor color, Integer shadowColor, Boolean bold, Boolean italic, Boolean underlined, Boolean strikethrough, Boolean obfuscated, ClickEvent clickEvent, HoverEvent hoverEvent, String insertion, FontDescription font) @ L59

  • 构造器名:Style
  • 源码定位:L59
  • 修饰符:private

参数:

  • color: TextColor
  • shadowColor: Integer
  • bold: Boolean
  • italic: Boolean
  • underlined: Boolean
  • strikethrough: Boolean
  • obfuscated: Boolean
  • clickEvent: ClickEvent
  • hoverEvent: HoverEvent
  • insertion: String
  • font: FontDescription

说明:

TODO

方法

下面的方法块按源码顺序生成。

private static Style create(Optional<TextColor> color, Optional<Integer> shadowColor, Optional<Boolean> bold, Optional<Boolean> italic, Optional<Boolean> underlined, Optional<Boolean> strikethrough, Optional<Boolean> obfuscated, Optional<ClickEvent> clickEvent, Optional<HoverEvent> hoverEvent, Optional<String> insertion, Optional<FontDescription> font) @ L30

  • 方法名:create
  • 源码定位:L30
  • 返回类型:Style
  • 修饰符:private static

参数:

  • color: Optional
  • shadowColor: Optional
  • bold: Optional
  • italic: Optional
  • underlined: Optional
  • strikethrough: Optional
  • obfuscated: Optional
  • clickEvent: Optional
  • hoverEvent: Optional
  • insertion: Optional
  • font: Optional

说明:

TODO

public TextColor getColor() @ L85

  • 方法名:getColor
  • 源码定位:L85
  • 返回类型:TextColor
  • 修饰符:public

参数:

说明:

TODO

public Integer getShadowColor() @ L89

  • 方法名:getShadowColor
  • 源码定位:L89
  • 返回类型:Integer
  • 修饰符:public

参数:

说明:

TODO

public boolean isBold() @ L93

  • 方法名:isBold
  • 源码定位:L93
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isItalic() @ L97

  • 方法名:isItalic
  • 源码定位:L97
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isStrikethrough() @ L101

  • 方法名:isStrikethrough
  • 源码定位:L101
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isUnderlined() @ L105

  • 方法名:isUnderlined
  • 源码定位:L105
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isObfuscated() @ L109

  • 方法名:isObfuscated
  • 源码定位:L109
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public boolean isEmpty() @ L113

  • 方法名:isEmpty
  • 源码定位:L113
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public ClickEvent getClickEvent() @ L117

  • 方法名:getClickEvent
  • 源码定位:L117
  • 返回类型:ClickEvent
  • 修饰符:public

参数:

说明:

TODO

public HoverEvent getHoverEvent() @ L121

  • 方法名:getHoverEvent
  • 源码定位:L121
  • 返回类型:HoverEvent
  • 修饰符:public

参数:

说明:

TODO

public String getInsertion() @ L125

  • 方法名:getInsertion
  • 源码定位:L125
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

public FontDescription getFont() @ L129

  • 方法名:getFont
  • 源码定位:L129
  • 返回类型:FontDescription
  • 修饰符:public

参数:

说明:

TODO

private static <T> Style checkEmptyAfterChange(Style newStyle, T previous, T next) @ L133

  • 方法名:checkEmptyAfterChange
  • 源码定位:L133
  • 返回类型: Style
  • 修饰符:private static

参数:

  • newStyle: Style
  • previous: T
  • next: T

说明:

TODO

public Style withColor(TextColor color) @ L137

  • 方法名:withColor
  • 源码定位:L137
  • 返回类型:Style
  • 修饰符:public

参数:

  • color: TextColor

说明:

TODO

public Style withColor(ChatFormatting color) @ L159

  • 方法名:withColor
  • 源码定位:L159
  • 返回类型:Style
  • 修饰符:public

参数:

  • color: ChatFormatting

说明:

TODO

public Style withColor(int color) @ L163

  • 方法名:withColor
  • 源码定位:L163
  • 返回类型:Style
  • 修饰符:public

参数:

  • color: int

说明:

TODO

public Style withShadowColor(int shadowColor) @ L167

  • 方法名:withShadowColor
  • 源码定位:L167
  • 返回类型:Style
  • 修饰符:public

参数:

  • shadowColor: int

说明:

TODO

public Style withoutShadow() @ L189

  • 方法名:withoutShadow
  • 源码定位:L189
  • 返回类型:Style
  • 修饰符:public

参数:

说明:

TODO

public Style withBold(Boolean bold) @ L193

  • 方法名:withBold
  • 源码定位:L193
  • 返回类型:Style
  • 修饰符:public

参数:

  • bold: Boolean

说明:

TODO

public Style withItalic(Boolean italic) @ L215

  • 方法名:withItalic
  • 源码定位:L215
  • 返回类型:Style
  • 修饰符:public

参数:

  • italic: Boolean

说明:

TODO

public Style withUnderlined(Boolean underlined) @ L237

  • 方法名:withUnderlined
  • 源码定位:L237
  • 返回类型:Style
  • 修饰符:public

参数:

  • underlined: Boolean

说明:

TODO

public Style withStrikethrough(Boolean strikethrough) @ L259

  • 方法名:withStrikethrough
  • 源码定位:L259
  • 返回类型:Style
  • 修饰符:public

参数:

  • strikethrough: Boolean

说明:

TODO

public Style withObfuscated(Boolean obfuscated) @ L281

  • 方法名:withObfuscated
  • 源码定位:L281
  • 返回类型:Style
  • 修饰符:public

参数:

  • obfuscated: Boolean

说明:

TODO

public Style withClickEvent(ClickEvent clickEvent) @ L303

  • 方法名:withClickEvent
  • 源码定位:L303
  • 返回类型:Style
  • 修饰符:public

参数:

  • clickEvent: ClickEvent

说明:

TODO

public Style withHoverEvent(HoverEvent hoverEvent) @ L325

  • 方法名:withHoverEvent
  • 源码定位:L325
  • 返回类型:Style
  • 修饰符:public

参数:

  • hoverEvent: HoverEvent

说明:

TODO

public Style withInsertion(String insertion) @ L347

  • 方法名:withInsertion
  • 源码定位:L347
  • 返回类型:Style
  • 修饰符:public

参数:

  • insertion: String

说明:

TODO

public Style withFont(FontDescription font) @ L369

  • 方法名:withFont
  • 源码定位:L369
  • 返回类型:Style
  • 修饰符:public

参数:

  • font: FontDescription

说明:

TODO

public Style applyFormat(ChatFormatting format) @ L391

  • 方法名:applyFormat
  • 源码定位:L391
  • 返回类型:Style
  • 修饰符:public

参数:

  • format: ChatFormatting

说明:

TODO

public Style applyLegacyFormat(ChatFormatting format) @ L425

  • 方法名:applyLegacyFormat
  • 源码定位:L425
  • 返回类型:Style
  • 修饰符:public

参数:

  • format: ChatFormatting

说明:

TODO

public Style applyFormats(ChatFormatting... formats) @ L464

  • 方法名:applyFormats
  • 源码定位:L464
  • 返回类型:Style
  • 修饰符:public

参数:

  • formats: ChatFormatting…

说明:

TODO

public Style applyTo(Style other) @ L501

  • 方法名:applyTo
  • 源码定位:L501
  • 返回类型:Style
  • 修饰符:public

参数:

  • other: Style

说明:

TODO

public String toString() @ L523

  • 方法名:toString
  • 源码定位:L523
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

public boolean equals(Object o) @ L580

  • 方法名:equals
  • 源码定位:L580
  • 返回类型:boolean
  • 修饰符:public

参数:

  • o: Object

说明:

TODO

public int hashCode() @ L601

  • 方法名:hashCode
  • 源码定位:L601
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

代码

public final class Style {
    public static final Style EMPTY = new Style(null, null, null, null, null, null, null, null, null, null, null);
    public static final int NO_SHADOW = 0;
    private final @Nullable TextColor color;
    private final @Nullable Integer shadowColor;
    private final @Nullable Boolean bold;
    private final @Nullable Boolean italic;
    private final @Nullable Boolean underlined;
    private final @Nullable Boolean strikethrough;
    private final @Nullable Boolean obfuscated;
    private final @Nullable ClickEvent clickEvent;
    private final @Nullable HoverEvent hoverEvent;
    private final @Nullable String insertion;
    private final @Nullable FontDescription font;
 
    private static Style create(
        Optional<TextColor> color,
        Optional<Integer> shadowColor,
        Optional<Boolean> bold,
        Optional<Boolean> italic,
        Optional<Boolean> underlined,
        Optional<Boolean> strikethrough,
        Optional<Boolean> obfuscated,
        Optional<ClickEvent> clickEvent,
        Optional<HoverEvent> hoverEvent,
        Optional<String> insertion,
        Optional<FontDescription> font
    ) {
        Style result = new Style(
            color.orElse(null),
            shadowColor.orElse(null),
            bold.orElse(null),
            italic.orElse(null),
            underlined.orElse(null),
            strikethrough.orElse(null),
            obfuscated.orElse(null),
            clickEvent.orElse(null),
            hoverEvent.orElse(null),
            insertion.orElse(null),
            font.orElse(null)
        );
        return result.equals(EMPTY) ? EMPTY : result;
    }
 
    private Style(
        @Nullable TextColor color,
        @Nullable Integer shadowColor,
        @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 FontDescription font
    ) {
        this.color = color;
        this.shadowColor = shadowColor;
        this.bold = bold;
        this.italic = italic;
        this.underlined = underlined;
        this.strikethrough = strikethrough;
        this.obfuscated = obfuscated;
        this.clickEvent = clickEvent;
        this.hoverEvent = hoverEvent;
        this.insertion = insertion;
        this.font = font;
    }
 
    public @Nullable TextColor getColor() {
        return this.color;
    }
 
    public @Nullable Integer getShadowColor() {
        return this.shadowColor;
    }
 
    public boolean isBold() {
        return this.bold == Boolean.TRUE;
    }
 
    public boolean isItalic() {
        return this.italic == Boolean.TRUE;
    }
 
    public boolean isStrikethrough() {
        return this.strikethrough == Boolean.TRUE;
    }
 
    public boolean isUnderlined() {
        return this.underlined == Boolean.TRUE;
    }
 
    public boolean isObfuscated() {
        return this.obfuscated == Boolean.TRUE;
    }
 
    public boolean isEmpty() {
        return this == EMPTY;
    }
 
    public @Nullable ClickEvent getClickEvent() {
        return this.clickEvent;
    }
 
    public @Nullable HoverEvent getHoverEvent() {
        return this.hoverEvent;
    }
 
    public @Nullable String getInsertion() {
        return this.insertion;
    }
 
    public FontDescription getFont() {
        return (FontDescription)(this.font != null ? this.font : FontDescription.DEFAULT);
    }
 
    private static <T> Style checkEmptyAfterChange(Style newStyle, @Nullable T previous, @Nullable T next) {
        return previous != null && next == null && newStyle.equals(EMPTY) ? EMPTY : newStyle;
    }
 
    public Style withColor(@Nullable TextColor color) {
        return Objects.equals(this.color, color)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.color,
                color
            );
    }
 
    public Style withColor(@Nullable ChatFormatting color) {
        return this.withColor(color != null ? TextColor.fromLegacyFormat(color) : null);
    }
 
    public Style withColor(int color) {
        return this.withColor(TextColor.fromRgb(color));
    }
 
    public Style withShadowColor(int shadowColor) {
        return Objects.equals(this.shadowColor, shadowColor)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.shadowColor,
                shadowColor
            );
    }
 
    public Style withoutShadow() {
        return this.withShadowColor(0);
    }
 
    public Style withBold(@Nullable Boolean bold) {
        return Objects.equals(this.bold, bold)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.bold,
                bold
            );
    }
 
    public Style withItalic(@Nullable Boolean italic) {
        return Objects.equals(this.italic, italic)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.italic,
                italic
            );
    }
 
    public Style withUnderlined(@Nullable Boolean underlined) {
        return Objects.equals(this.underlined, underlined)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.underlined,
                underlined
            );
    }
 
    public Style withStrikethrough(@Nullable Boolean strikethrough) {
        return Objects.equals(this.strikethrough, strikethrough)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.strikethrough,
                strikethrough
            );
    }
 
    public Style withObfuscated(@Nullable Boolean obfuscated) {
        return Objects.equals(this.obfuscated, obfuscated)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.obfuscated,
                obfuscated
            );
    }
 
    public Style withClickEvent(@Nullable ClickEvent clickEvent) {
        return Objects.equals(this.clickEvent, clickEvent)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.clickEvent,
                clickEvent
            );
    }
 
    public Style withHoverEvent(@Nullable HoverEvent hoverEvent) {
        return Objects.equals(this.hoverEvent, hoverEvent)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    hoverEvent,
                    this.insertion,
                    this.font
                ),
                this.hoverEvent,
                hoverEvent
            );
    }
 
    public Style withInsertion(@Nullable String insertion) {
        return Objects.equals(this.insertion, insertion)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    insertion,
                    this.font
                ),
                this.insertion,
                insertion
            );
    }
 
    public Style withFont(@Nullable FontDescription font) {
        return Objects.equals(this.font, font)
            ? this
            : checkEmptyAfterChange(
                new Style(
                    this.color,
                    this.shadowColor,
                    this.bold,
                    this.italic,
                    this.underlined,
                    this.strikethrough,
                    this.obfuscated,
                    this.clickEvent,
                    this.hoverEvent,
                    this.insertion,
                    font
                ),
                this.font,
                font
            );
    }
 
    public Style applyFormat(ChatFormatting format) {
        TextColor color = this.color;
        Boolean bold = this.bold;
        Boolean italic = this.italic;
        Boolean strikethrough = this.strikethrough;
        Boolean underlined = this.underlined;
        Boolean obfuscated = this.obfuscated;
        switch (format) {
            case OBFUSCATED:
                obfuscated = true;
                break;
            case BOLD:
                bold = true;
                break;
            case STRIKETHROUGH:
                strikethrough = true;
                break;
            case UNDERLINE:
                underlined = true;
                break;
            case ITALIC:
                italic = true;
                break;
            case RESET:
                return EMPTY;
            default:
                color = TextColor.fromLegacyFormat(format);
        }
 
        return new Style(
            color, this.shadowColor, bold, italic, underlined, strikethrough, obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.font
        );
    }
 
    public Style applyLegacyFormat(ChatFormatting format) {
        TextColor color = this.color;
        Boolean bold = this.bold;
        Boolean italic = this.italic;
        Boolean strikethrough = this.strikethrough;
        Boolean underlined = this.underlined;
        Boolean obfuscated = this.obfuscated;
        switch (format) {
            case OBFUSCATED:
                obfuscated = true;
                break;
            case BOLD:
                bold = true;
                break;
            case STRIKETHROUGH:
                strikethrough = true;
                break;
            case UNDERLINE:
                underlined = true;
                break;
            case ITALIC:
                italic = true;
                break;
            case RESET:
                return EMPTY;
            default:
                obfuscated = false;
                bold = false;
                strikethrough = false;
                underlined = false;
                italic = false;
                color = TextColor.fromLegacyFormat(format);
        }
 
        return new Style(
            color, this.shadowColor, bold, italic, underlined, strikethrough, obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.font
        );
    }
 
    public Style applyFormats(ChatFormatting... formats) {
        TextColor color = this.color;
        Boolean bold = this.bold;
        Boolean italic = this.italic;
        Boolean strikethrough = this.strikethrough;
        Boolean underlined = this.underlined;
        Boolean obfuscated = this.obfuscated;
 
        for (ChatFormatting format : formats) {
            switch (format) {
                case OBFUSCATED:
                    obfuscated = true;
                    break;
                case BOLD:
                    bold = true;
                    break;
                case STRIKETHROUGH:
                    strikethrough = true;
                    break;
                case UNDERLINE:
                    underlined = true;
                    break;
                case ITALIC:
                    italic = true;
                    break;
                case RESET:
                    return EMPTY;
                default:
                    color = TextColor.fromLegacyFormat(format);
            }
        }
 
        return new Style(
            color, this.shadowColor, bold, italic, underlined, strikethrough, obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.font
        );
    }
 
    public Style applyTo(Style other) {
        if (this == EMPTY) {
            return other;
        } else {
            return other == EMPTY
                ? this
                : new Style(
                    this.color != null ? this.color : other.color,
                    this.shadowColor != null ? this.shadowColor : other.shadowColor,
                    this.bold != null ? this.bold : other.bold,
                    this.italic != null ? this.italic : other.italic,
                    this.underlined != null ? this.underlined : other.underlined,
                    this.strikethrough != null ? this.strikethrough : other.strikethrough,
                    this.obfuscated != null ? this.obfuscated : other.obfuscated,
                    this.clickEvent != null ? this.clickEvent : other.clickEvent,
                    this.hoverEvent != null ? this.hoverEvent : other.hoverEvent,
                    this.insertion != null ? this.insertion : other.insertion,
                    this.font != null ? this.font : other.font
                );
        }
    }
 
    @Override
    public String toString() {
        final StringBuilder result = new StringBuilder("{");
 
        class Collector {
            private boolean isNotFirst;
 
            Collector() {
                Objects.requireNonNull(Style.this);
                super();
            }
 
            private void prependSeparator() {
                if (this.isNotFirst) {
                    result.append(',');
                }
 
                this.isNotFirst = true;
            }
 
            private void addFlagString(String name, @Nullable Boolean value) {
                if (value != null) {
                    this.prependSeparator();
                    if (!value) {
                        result.append('!');
                    }
 
                    result.append(name);
                }
            }
 
            private void addValueString(String name, @Nullable Object value) {
                if (value != null) {
                    this.prependSeparator();
                    result.append(name);
                    result.append('=');
                    result.append(value);
                }
            }
        }
 
        Collector collector = new Collector();
        collector.addValueString("color", this.color);
        collector.addValueString("shadowColor", this.shadowColor);
        collector.addFlagString("bold", this.bold);
        collector.addFlagString("italic", this.italic);
        collector.addFlagString("underlined", this.underlined);
        collector.addFlagString("strikethrough", this.strikethrough);
        collector.addFlagString("obfuscated", this.obfuscated);
        collector.addValueString("clickEvent", this.clickEvent);
        collector.addValueString("hoverEvent", this.hoverEvent);
        collector.addValueString("insertion", this.insertion);
        collector.addValueString("font", this.font);
        result.append("}");
        return result.toString();
    }
 
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else {
            return !(o instanceof Style style)
                ? false
                : this.bold == style.bold
                    && Objects.equals(this.getColor(), style.getColor())
                    && Objects.equals(this.getShadowColor(), style.getShadowColor())
                    && this.italic == style.italic
                    && this.obfuscated == style.obfuscated
                    && this.strikethrough == style.strikethrough
                    && this.underlined == style.underlined
                    && Objects.equals(this.clickEvent, style.clickEvent)
                    && Objects.equals(this.hoverEvent, style.hoverEvent)
                    && Objects.equals(this.insertion, style.insertion)
                    && Objects.equals(this.font, style.font);
        }
    }
 
    @Override
    public int hashCode() {
        return Objects.hash(
            this.color,
            this.shadowColor,
            this.bold,
            this.italic,
            this.underlined,
            this.strikethrough,
            this.obfuscated,
            this.clickEvent,
            this.hoverEvent,
            this.insertion
        );
    }
 
    public static class Serializer {
        public static final MapCodec<Style> MAP_CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    TextColor.CODEC.optionalFieldOf("color").forGetter(o -> Optional.ofNullable(o.color)),
                    ExtraCodecs.ARGB_COLOR_CODEC.optionalFieldOf("shadow_color").forGetter(o -> Optional.ofNullable(o.shadowColor)),
                    Codec.BOOL.optionalFieldOf("bold").forGetter(o -> Optional.ofNullable(o.bold)),
                    Codec.BOOL.optionalFieldOf("italic").forGetter(o -> Optional.ofNullable(o.italic)),
                    Codec.BOOL.optionalFieldOf("underlined").forGetter(o -> Optional.ofNullable(o.underlined)),
                    Codec.BOOL.optionalFieldOf("strikethrough").forGetter(o -> Optional.ofNullable(o.strikethrough)),
                    Codec.BOOL.optionalFieldOf("obfuscated").forGetter(o -> Optional.ofNullable(o.obfuscated)),
                    ClickEvent.CODEC.optionalFieldOf("click_event").forGetter(o -> Optional.ofNullable(o.clickEvent)),
                    HoverEvent.CODEC.optionalFieldOf("hover_event").forGetter(o -> Optional.ofNullable(o.hoverEvent)),
                    Codec.STRING.optionalFieldOf("insertion").forGetter(o -> Optional.ofNullable(o.insertion)),
                    FontDescription.CODEC.optionalFieldOf("font").forGetter(o -> Optional.ofNullable(o.font))
                )
                .apply(i, Style::create)
        );
        public static final Codec<Style> CODEC = MAP_CODEC.codec();
        public static final StreamCodec<RegistryFriendlyByteBuf, Style> TRUSTED_STREAM_CODEC = ByteBufCodecs.fromCodecWithRegistriesTrusted(CODEC);
    }
}

引用的其他类

  • ChatFormatting

    • 引用位置: 参数
  • ClickEvent

    • 引用位置: 参数/字段/返回值
  • FontDescription

    • 引用位置: 参数/字段/返回值
  • HoverEvent

    • 引用位置: 参数/字段/返回值
  • TextColor

    • 引用位置: 参数/字段/方法调用/返回值
    • 关联成员: TextColor.fromLegacyFormat(), TextColor.fromRgb()
  • ByteBufCodecs

    • 引用位置: 方法调用
    • 关联成员: ByteBufCodecs.fromCodecWithRegistriesTrusted()