Achievement .java

net.minecraft.stats.Achievement (class): members: setStatStringFormatter, statStringFormatter, parentAchievement, displayColumn, func_150953_b, displayRow.

net.minecraft.statsclass170 linescommonextends StatBase5.1 KB

API Surface (9)

Achievement initIndependentStat()
Achievement setSpecial()
Achievement registerStat()
boolean isAchievement()
IChatComponent getStatName()
Achievement func_150953_b(Class <? extends IJsonSerializable > p_150953_1_)
String getDescription()
Achievement setStatStringFormatter(IStatStringFormat statStringFormatterIn)
boolean getSpecial()

Fields & Constants (7)

displayColumn
displayRow
parentAchievement
achievementDescription
statStringFormatter
theItemStack
isSpecial

String literals (2)

"achievement."
".desc"

Full Source

Achievement.java170 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.stats;
2
3
import net.minecraft.block.Block;
4
import net.minecraft.item.Item;
5
import net.minecraft.item.ItemStack;
6
import net.minecraft.util.ChatComponentTranslation;
7
import net.minecraft.util.EnumChatFormatting;
8
import net.minecraft.util.IChatComponent;
9
import net.minecraft.util.IJsonSerializable;
10
import net.minecraft.util.StatCollector;
11
12
public class Achievement extends StatBase
13
{
14
    /**
15
     * Is the column (related to center of achievement gui, in 24 pixels unit) that the achievement will be displayed.
16
     */
17
    public final int displayColumn;
18
19
    /**
20
     * Is the row (related to center of achievement gui, in 24 pixels unit) that the achievement will be displayed.
21
     */
22
    public final int displayRow;
23
24
    /**
25
     * Holds the parent achievement, that must be taken before this achievement is avaiable.
26
     */
27
    public final Achievement parentAchievement;
28
29
    /**
30
     * Holds the description of the achievement, ready to be formatted and/or displayed.
31
     */
32
    private final String achievementDescription;
33
34
    /**
35
     * Holds a string formatter for the achievement, some of then needs extra dynamic info - like the key used to open
36
     * the inventory.
37
     */
38
    private IStatStringFormat statStringFormatter;
39
40
    /**
41
     * Holds the ItemStack that will be used to draw the achievement into the GUI.
42
     */
43
    public final ItemStack theItemStack;
44
45
    /**
46
     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
47
     * achieve.
48
     */
49
    private boolean isSpecial;
50
51
    public Achievement(String statIdIn, String unlocalizedName, int column, int row, Item itemIn, Achievement parent)
52
    {
53
        this(statIdIn, unlocalizedName, column, row, new ItemStack(itemIn), parent);
54
    }
55
56
    public Achievement(String statIdIn, String unlocalizedName, int column, int row, Block blockIn, Achievement parent)
57
    {
58
        this(statIdIn, unlocalizedName, column, row, new ItemStack(blockIn), parent);
59
    }
60
61
    public Achievement(String statIdIn, String unlocalizedName, int column, int row, ItemStack stack, Achievement parent)
62
    {
63
        super(statIdIn, new ChatComponentTranslation("achievement." + unlocalizedName, new Object[0]));
64
        this.theItemStack = stack;
65
        this.achievementDescription = "achievement." + unlocalizedName + ".desc";
66
        this.displayColumn = column;
67
        this.displayRow = row;
68
69
        if (column < AchievementList.minDisplayColumn)
70
        {
71
            AchievementList.minDisplayColumn = column;
72
        }
73
74
        if (row < AchievementList.minDisplayRow)
75
        {
76
            AchievementList.minDisplayRow = row;
77
        }
78
79
        if (column > AchievementList.maxDisplayColumn)
80
        {
81
            AchievementList.maxDisplayColumn = column;
82
        }
83
84
        if (row > AchievementList.maxDisplayRow)
85
        {
86
            AchievementList.maxDisplayRow = row;
87
        }
88
89
        this.parentAchievement = parent;
90
    }
91
92
    /**
93
     * Initializes the current stat as independent (i.e., lacking prerequisites for being updated) and returns the
94
     * current instance.
95
     */
96
    public Achievement initIndependentStat()
97
    {
98
        this.isIndependent = true;
99
        return this;
100
    }
101
102
    /**
103
     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
104
     * achieve.
105
     */
106
    public Achievement setSpecial()
107
    {
108
        this.isSpecial = true;
109
        return this;
110
    }
111
112
    /**
113
     * Register the stat into StatList.
114
     */
115
    public Achievement registerStat()
116
    {
117
        super.registerStat();
118
        AchievementList.achievementList.add(this);
119
        return this;
120
    }
121
122
    /**
123
     * Returns whether or not the StatBase-derived class is a statistic (running counter) or an achievement (one-shot).
124
     */
125
    public boolean isAchievement()
126
    {
127
        return true;
128
    }
129
130
    public IChatComponent getStatName()
131
    {
132
        IChatComponent ichatcomponent = super.getStatName();
133
        ichatcomponent.getChatStyle().setColor(this.getSpecial() ? EnumChatFormatting.DARK_PURPLE : EnumChatFormatting.GREEN);
134
        return ichatcomponent;
135
    }
136
137
    public Achievement func_150953_b(Class <? extends IJsonSerializable > p_150953_1_)
138
    {
139
        return (Achievement)super.func_150953_b(p_150953_1_);
140
    }
141
142
    /**
143
     * Returns the fully description of the achievement - ready to be displayed on screen.
144
     */
145
    public String getDescription()
146
    {
147
        return this.statStringFormatter != null ? this.statStringFormatter.formatString(StatCollector.translateToLocal(this.achievementDescription)) : StatCollector.translateToLocal(this.achievementDescription);
148
    }
149
150
    /**
151
     * Defines a string formatter for the achievement.
152
     *  
153
     * @param statStringFormatterIn 1.8.9
154
     */
155
    public Achievement setStatStringFormatter(IStatStringFormat statStringFormatterIn)
156
    {
157
        this.statStringFormatter = statStringFormatterIn;
158
        return this;
159
    }
160
161
    /**
162
     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
163
     * achieve.
164
     */
165
    public boolean getSpecial()
166
    {
167
        return this.isSpecial;
168
    }
169
}
170

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