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