001package net.minecraft.stats;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.block.Block;
006import net.minecraft.item.Item;
007import net.minecraft.item.ItemStack;
008import net.minecraft.util.StatCollector;
009
010public class Achievement extends StatBase
011{
012    /**
013     * Is the column (related to center of achievement gui, in 24 pixels unit) that the achievement will be displayed.
014     */
015    public final int displayColumn;
016
017    /**
018     * Is the row (related to center of achievement gui, in 24 pixels unit) that the achievement will be displayed.
019     */
020    public final int displayRow;
021
022    /**
023     * Holds the parent achievement, that must be taken before this achievement is avaiable.
024     */
025    public final Achievement parentAchievement;
026
027    /**
028     * Holds the description of the achievement, ready to be formatted and/or displayed.
029     */
030    private final String achievementDescription;
031    @SideOnly(Side.CLIENT)
032
033    /**
034     * Holds a string formatter for the achievement, some of then needs extra dynamic info - like the key used to open
035     * the inventory.
036     */
037    private IStatStringFormat statStringFormatter;
038
039    /**
040     * Holds the ItemStack that will be used to draw the achievement into the GUI.
041     */
042    public final ItemStack theItemStack;
043
044    /**
045     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
046     * achieve.
047     */
048    private boolean isSpecial;
049
050    public Achievement(int par1, String par2Str, int par3, int par4, Item par5Item, Achievement par6Achievement)
051    {
052        this(par1, par2Str, par3, par4, new ItemStack(par5Item), par6Achievement);
053    }
054
055    public Achievement(int par1, String par2Str, int par3, int par4, Block par5Block, Achievement par6Achievement)
056    {
057        this(par1, par2Str, par3, par4, new ItemStack(par5Block), par6Achievement);
058    }
059
060    public Achievement(int par1, String par2Str, int par3, int par4, ItemStack par5ItemStack, Achievement par6Achievement)
061    {
062        super(5242880 + par1, "achievement." + par2Str);
063        this.theItemStack = par5ItemStack;
064        this.achievementDescription = "achievement." + par2Str + ".desc";
065        this.displayColumn = par3;
066        this.displayRow = par4;
067
068        if (par3 < AchievementList.minDisplayColumn)
069        {
070            AchievementList.minDisplayColumn = par3;
071        }
072
073        if (par4 < AchievementList.minDisplayRow)
074        {
075            AchievementList.minDisplayRow = par4;
076        }
077
078        if (par3 > AchievementList.maxDisplayColumn)
079        {
080            AchievementList.maxDisplayColumn = par3;
081        }
082
083        if (par4 > AchievementList.maxDisplayRow)
084        {
085            AchievementList.maxDisplayRow = par4;
086        }
087
088        this.parentAchievement = par6Achievement;
089    }
090
091    /**
092     * Indicates whether or not the given achievement or statistic is independent (i.e., lacks prerequisites for being
093     * update).
094     */
095    public Achievement setIndependent()
096    {
097        this.isIndependent = true;
098        return this;
099    }
100
101    /**
102     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
103     * achieve.
104     */
105    public Achievement setSpecial()
106    {
107        this.isSpecial = true;
108        return this;
109    }
110
111    /**
112     * Adds the achievement on the internal list of registered achievements, also, it's check for duplicated id's.
113     */
114    public Achievement registerAchievement()
115    {
116        super.registerStat();
117        AchievementList.achievementList.add(this);
118        return this;
119    }
120
121    @SideOnly(Side.CLIENT)
122
123    /**
124     * Returns whether or not the StatBase-derived class is a statistic (running counter) or an achievement (one-shot).
125     */
126    public boolean isAchievement()
127    {
128        return true;
129    }
130
131    @SideOnly(Side.CLIENT)
132
133    /**
134     * Returns the fully description of the achievement - ready to be displayed on screen.
135     */
136    public String getDescription()
137    {
138        return this.statStringFormatter != null ? this.statStringFormatter.formatString(StatCollector.translateToLocal(this.achievementDescription)) : StatCollector.translateToLocal(this.achievementDescription);
139    }
140
141    @SideOnly(Side.CLIENT)
142
143    /**
144     * Defines a string formatter for the achievement.
145     */
146    public Achievement setStatStringFormatter(IStatStringFormat par1IStatStringFormat)
147    {
148        this.statStringFormatter = par1IStatStringFormat;
149        return this;
150    }
151
152    @SideOnly(Side.CLIENT)
153
154    /**
155     * Special achievements have a 'spiked' (on normal texture pack) frame, special achievements are the hardest ones to
156     * achieve.
157     */
158    public boolean getSpecial()
159    {
160        return this.isSpecial;
161    }
162
163    /**
164     * Register the stat into StatList.
165     */
166    public StatBase registerStat()
167    {
168        return this.registerAchievement();
169    }
170
171    /**
172     * Initializes the current stat as independent (i.e., lacking prerequisites for being updated) and returns the
173     * current instance.
174     */
175    public StatBase initIndependentStat()
176    {
177        return this.setIndependent();
178    }
179}