StatBase .java

net.minecraft.stats.StatBase (class): members: createChatComponent, distanceStatType, field_111202_k, field_150956_d, simpleStatType, decimalFormat, this.

net.minecraft.statsclass181 linescommon5.6 KB

API Surface (16)

String format(int number)
String format(int number)
String format(int number)
String format(int number)
StatBase initIndependentStat()
StatBase registerStat()
boolean isAchievement()
String format(int p_75968_1_)
IChatComponent getStatName()
IChatComponent createChatComponent()
boolean equals(Object p_equals_1_)
int hashCode()
String toString()
IScoreObjectiveCriteria getCriteria()
Class <? extends IJsonSerializable > func_150954_l()
StatBase func_150953_b(Class <? extends IJsonSerializable > p_150953_1_)

Fields & Constants (13)

statId
statName
isIndependent
type
objectiveCriteria
field_150956_d
numberFormat
simpleStatType
decimalFormat
timeStatType
distanceStatType
field_111202_k
this

String literals (7)

"Duplicate stat id: \""
"\" and \""
"Stat{id="
", nameId="
", awardLocallyOnly="
", formatter="
", objectiveCriteria="

Full Source

StatBase.java181 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.stats;
2
3
import java.text.DecimalFormat;
4
import java.text.NumberFormat;
5
import java.util.Locale;
6
import net.minecraft.event.HoverEvent;
7
import net.minecraft.scoreboard.IScoreObjectiveCriteria;
8
import net.minecraft.util.ChatComponentText;
9
import net.minecraft.util.EnumChatFormatting;
10
import net.minecraft.util.IChatComponent;
11
import net.minecraft.util.IJsonSerializable;
12
13
public class StatBase
14
{
15
    /** The Stat ID */
16
    public final String statId;
17
18
    /** The Stat name */
19
    private final IChatComponent statName;
20
    public boolean isIndependent;
21
    private final IStatType type;
22
    private final IScoreObjectiveCriteria objectiveCriteria;
23
    private Class <? extends IJsonSerializable > field_150956_d;
24
    private static NumberFormat numberFormat = NumberFormat.getIntegerInstance(Locale.US);
25
    public static IStatType simpleStatType = new IStatType()
26
    {
27
        public String format(int number)
28
        {
29
            return StatBase.numberFormat.format((long)number);
30
        }
31
    };
32
    private static DecimalFormat decimalFormat = new DecimalFormat("########0.00");
33
    public static IStatType timeStatType = new IStatType()
34
    {
35
        public String format(int number)
36
        {
37
            double d0 = (double)number / 20.0D;
38
            double d1 = d0 / 60.0D;
39
            double d2 = d1 / 60.0D;
40
            double d3 = d2 / 24.0D;
41
            double d4 = d3 / 365.0D;
42
            return d4 > 0.5D ? StatBase.decimalFormat.format(d4) + " y" : (d3 > 0.5D ? StatBase.decimalFormat.format(d3) + " d" : (d2 > 0.5D ? StatBase.decimalFormat.format(d2) + " h" : (d1 > 0.5D ? StatBase.decimalFormat.format(d1) + " m" : d0 + " s")));
43
        }
44
    };
45
    public static IStatType distanceStatType = new IStatType()
46
    {
47
        public String format(int number)
48
        {
49
            double d0 = (double)number / 100.0D;
50
            double d1 = d0 / 1000.0D;
51
            return d1 > 0.5D ? StatBase.decimalFormat.format(d1) + " km" : (d0 > 0.5D ? StatBase.decimalFormat.format(d0) + " m" : number + " cm");
52
        }
53
    };
54
    public static IStatType field_111202_k = new IStatType()
55
    {
56
        public String format(int number)
57
        {
58
            return StatBase.decimalFormat.format((double)number * 0.1D);
59
        }
60
    };
61
62
    public StatBase(String statIdIn, IChatComponent statNameIn, IStatType typeIn)
63
    {
64
        this.statId = statIdIn;
65
        this.statName = statNameIn;
66
        this.type = typeIn;
67
        this.objectiveCriteria = new ObjectiveStat(this);
68
        IScoreObjectiveCriteria.INSTANCES.put(this.objectiveCriteria.getName(), this.objectiveCriteria);
69
    }
70
71
    public StatBase(String statIdIn, IChatComponent statNameIn)
72
    {
73
        this(statIdIn, statNameIn, simpleStatType);
74
    }
75
76
    /**
77
     * Initializes the current stat as independent (i.e., lacking prerequisites for being updated) and returns the
78
     * current instance.
79
     */
80
    public StatBase initIndependentStat()
81
    {
82
        this.isIndependent = true;
83
        return this;
84
    }
85
86
    /**
87
     * Register the stat into StatList.
88
     */
89
    public StatBase registerStat()
90
    {
91
        if (StatList.oneShotStats.containsKey(this.statId))
92
        {
93
            throw new RuntimeException("Duplicate stat id: \"" + ((StatBase)StatList.oneShotStats.get(this.statId)).statName + "\" and \"" + this.statName + "\" at id " + this.statId);
94
        }
95
        else
96
        {
97
            StatList.allStats.add(this);
98
            StatList.oneShotStats.put(this.statId, this);
99
            return this;
100
        }
101
    }
102
103
    /**
104
     * Returns whether or not the StatBase-derived class is a statistic (running counter) or an achievement (one-shot).
105
     */
106
    public boolean isAchievement()
107
    {
108
        return false;
109
    }
110
111
    public String format(int p_75968_1_)
112
    {
113
        return this.type.format(p_75968_1_);
114
    }
115
116
    public IChatComponent getStatName()
117
    {
118
        IChatComponent ichatcomponent = this.statName.createCopy();
119
        ichatcomponent.getChatStyle().setColor(EnumChatFormatting.GRAY);
120
        ichatcomponent.getChatStyle().setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ACHIEVEMENT, new ChatComponentText(this.statId)));
121
        return ichatcomponent;
122
    }
123
124
    /**
125
     * 1.8.9
126
     */
127
    public IChatComponent createChatComponent()
128
    {
129
        IChatComponent ichatcomponent = this.getStatName();
130
        IChatComponent ichatcomponent1 = (new ChatComponentText("[")).appendSibling(ichatcomponent).appendText("]");
131
        ichatcomponent1.setChatStyle(ichatcomponent.getChatStyle());
132
        return ichatcomponent1;
133
    }
134
135
    public boolean equals(Object p_equals_1_)
136
    {
137
        if (this == p_equals_1_)
138
        {
139
            return true;
140
        }
141
        else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass())
142
        {
143
            StatBase statbase = (StatBase)p_equals_1_;
144
            return this.statId.equals(statbase.statId);
145
        }
146
        else
147
        {
148
            return false;
149
        }
150
    }
151
152
    public int hashCode()
153
    {
154
        return this.statId.hashCode();
155
    }
156
157
    public String toString()
158
    {
159
        return "Stat{id=" + this.statId + ", nameId=" + this.statName + ", awardLocallyOnly=" + this.isIndependent + ", formatter=" + this.type + ", objectiveCriteria=" + this.objectiveCriteria + '}';
160
    }
161
162
    /**
163
     * 1.8.9
164
     */
165
    public IScoreObjectiveCriteria getCriteria()
166
    {
167
        return this.objectiveCriteria;
168
    }
169
170
    public Class <? extends IJsonSerializable > func_150954_l()
171
    {
172
        return this.field_150956_d;
173
    }
174
175
    public StatBase func_150953_b(Class <? extends IJsonSerializable > p_150953_1_)
176
    {
177
        this.field_150956_d = p_150953_1_;
178
        return this;
179
    }
180
}
181

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