ChatComponentStyle .java

net.minecraft.util.ChatComponentStyle (class, 149 lines): members: createDeepCopyIterator, siblings, style, getUnformattedText, getFormattedText, iterator.

net.minecraft.utilclass149 linescommon4.3 KB

Implements

API Surface (14)

IChatComponent appendSibling(IChatComponent component)
List<IChatComponent> getSiblings()
IChatComponent appendText(String text)
IChatComponent setChatStyle(ChatStyle style)
ChatStyle getChatStyle()
Iterator<IChatComponent> iterator()
String getUnformattedText()
String getFormattedText()
Iterator<IChatComponent> createDeepCopyIterator(Iterable<IChatComponent> components)
Iterator<IChatComponent> apply(IChatComponent p_apply_1_)
IChatComponent apply(IChatComponent p_apply_1_)
boolean equals(Object p_equals_1_)
int hashCode()
String toString()

Fields & Constants (2)

siblings
style

String literals (2)

"BaseComponent{style="
", siblings="

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ChatComponentStyle.java149 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import com.google.common.base.Function;
4
import com.google.common.collect.Iterators;
5
import com.google.common.collect.Lists;
6
import java.util.Iterator;
7
import java.util.List;
8
9
public abstract class ChatComponentStyle implements IChatComponent
10
{
11
    protected List<IChatComponent> siblings = Lists.<IChatComponent>newArrayList();
12
    private ChatStyle style;
13
14
    /**
15
     * Appends the given component to the end of this one.
16
     */
17
    public IChatComponent appendSibling(IChatComponent component)
18
    {
19
        component.getChatStyle().setParentStyle(this.getChatStyle());
20
        this.siblings.add(component);
21
        return this;
22
    }
23
24
    public List<IChatComponent> getSiblings()
25
    {
26
        return this.siblings;
27
    }
28
29
    /**
30
     * Appends the given text to the end of this component.
31
     */
32
    public IChatComponent appendText(String text)
33
    {
34
        return this.appendSibling(new ChatComponentText(text));
35
    }
36
37
    public IChatComponent setChatStyle(ChatStyle style)
38
    {
39
        this.style = style;
40
41
        for (IChatComponent ichatcomponent : this.siblings)
42
        {
43
            ichatcomponent.getChatStyle().setParentStyle(this.getChatStyle());
44
        }
45
46
        return this;
47
    }
48
49
    public ChatStyle getChatStyle()
50
    {
51
        if (this.style == null)
52
        {
53
            this.style = new ChatStyle();
54
55
            for (IChatComponent ichatcomponent : this.siblings)
56
            {
57
                ichatcomponent.getChatStyle().setParentStyle(this.style);
58
            }
59
        }
60
61
        return this.style;
62
    }
63
64
    public Iterator<IChatComponent> iterator()
65
    {
66
        return Iterators.<IChatComponent>concat(Iterators.<IChatComponent>forArray(new ChatComponentStyle[] {this}), createDeepCopyIterator(this.siblings));
67
    }
68
69
    /**
70
     * Get the text of this component, <em>and all child components</em>, with all special formatting codes removed.
71
     */
72
    public final String getUnformattedText()
73
    {
74
        StringBuilder stringbuilder = new StringBuilder();
75
76
        for (IChatComponent ichatcomponent : this)
77
        {
78
            stringbuilder.append(ichatcomponent.getUnformattedTextForChat());
79
        }
80
81
        return stringbuilder.toString();
82
    }
83
84
    /**
85
     * Gets the text of this component, with formatting codes added for rendering.
86
     */
87
    public final String getFormattedText()
88
    {
89
        StringBuilder stringbuilder = new StringBuilder();
90
91
        for (IChatComponent ichatcomponent : this)
92
        {
93
            stringbuilder.append(ichatcomponent.getChatStyle().getFormattingCode());
94
            stringbuilder.append(ichatcomponent.getUnformattedTextForChat());
95
            stringbuilder.append((Object)EnumChatFormatting.RESET);
96
        }
97
98
        return stringbuilder.toString();
99
    }
100
101
    public static Iterator<IChatComponent> createDeepCopyIterator(Iterable<IChatComponent> components)
102
    {
103
        Iterator<IChatComponent> iterator = Iterators.concat(Iterators.transform(components.iterator(), new Function<IChatComponent, Iterator<IChatComponent>>()
104
        {
105
            public Iterator<IChatComponent> apply(IChatComponent p_apply_1_)
106
            {
107
                return p_apply_1_.iterator();
108
            }
109
        }));
110
        iterator = Iterators.transform(iterator, new Function<IChatComponent, IChatComponent>()
111
        {
112
            public IChatComponent apply(IChatComponent p_apply_1_)
113
            {
114
                IChatComponent ichatcomponent = p_apply_1_.createCopy();
115
                ichatcomponent.setChatStyle(ichatcomponent.getChatStyle().createDeepCopy());
116
                return ichatcomponent;
117
            }
118
        });
119
        return iterator;
120
    }
121
122
    public boolean equals(Object p_equals_1_)
123
    {
124
        if (this == p_equals_1_)
125
        {
126
            return true;
127
        }
128
        else if (!(p_equals_1_ instanceof ChatComponentStyle))
129
        {
130
            return false;
131
        }
132
        else
133
        {
134
            ChatComponentStyle chatcomponentstyle = (ChatComponentStyle)p_equals_1_;
135
            return this.siblings.equals(chatcomponentstyle.siblings) && this.getChatStyle().equals(chatcomponentstyle.getChatStyle());
136
        }
137
    }
138
139
    public int hashCode()
140
    {
141
        return 31 * this.style.hashCode() + this.siblings.hashCode();
142
    }
143
144
    public String toString()
145
    {
146
        return "BaseComponent{style=" + this.style + ", siblings=" + this.siblings + '}';
147
    }
148
}
149

Deobfuscated MCP 1.8.9 source of ChatComponentStyle from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/ChatComponentStyle.java), stored verbatim.