001 package net.minecraft.stats;
002
003 import cpw.mods.fml.relauncher.Side;
004 import cpw.mods.fml.relauncher.SideOnly;
005 import java.text.DecimalFormat;
006 import java.text.NumberFormat;
007 import java.util.Locale;
008 import net.minecraft.util.StatCollector;
009
010 public class StatBase
011 {
012 /** The Stat ID */
013 public final int statId;
014
015 /** The Stat name */
016 public final String statName;
017 public boolean isIndependent;
018
019 /** Holds the GUID of the stat. */
020 public String statGuid;
021 private final IStatType type;
022 private static NumberFormat numberFormat = NumberFormat.getIntegerInstance(Locale.US);
023 public static IStatType simpleStatType = new StatTypeSimple();
024 private static DecimalFormat decimalFormat = new DecimalFormat("########0.00");
025 public static IStatType timeStatType = new StatTypeTime();
026 public static IStatType distanceStatType = new StatTypeDistance();
027
028 public StatBase(int par1, String par2Str, IStatType par3IStatType)
029 {
030 this.isIndependent = false;
031 this.statId = par1;
032 this.statName = par2Str;
033 this.type = par3IStatType;
034 }
035
036 public StatBase(int par1, String par2Str)
037 {
038 this(par1, par2Str, simpleStatType);
039 }
040
041 /**
042 * Initializes the current stat as independent (i.e., lacking prerequisites for being updated) and returns the
043 * current instance.
044 */
045 public StatBase initIndependentStat()
046 {
047 this.isIndependent = true;
048 return this;
049 }
050
051 /**
052 * Register the stat into StatList.
053 */
054 public StatBase registerStat()
055 {
056 if (StatList.oneShotStats.containsKey(Integer.valueOf(this.statId)))
057 {
058 throw new RuntimeException("Duplicate stat id: \"" + ((StatBase)StatList.oneShotStats.get(Integer.valueOf(this.statId))).statName + "\" and \"" + this.statName + "\" at id " + this.statId);
059 }
060 else
061 {
062 StatList.allStats.add(this);
063 StatList.oneShotStats.put(Integer.valueOf(this.statId), this);
064 this.statGuid = AchievementMap.getGuid(this.statId);
065 return this;
066 }
067 }
068
069 @SideOnly(Side.CLIENT)
070
071 /**
072 * Returns whether or not the StatBase-derived class is a statistic (running counter) or an achievement (one-shot).
073 */
074 public boolean isAchievement()
075 {
076 return false;
077 }
078
079 @SideOnly(Side.CLIENT)
080 public String func_75968_a(int par1)
081 {
082 return this.type.format(par1);
083 }
084
085 @SideOnly(Side.CLIENT)
086 public String getName()
087 {
088 return this.statName;
089 }
090
091 public String toString()
092 {
093 return StatCollector.translateToLocal(this.statName);
094 }
095
096 @SideOnly(Side.CLIENT)
097
098 static NumberFormat getNumberFormat()
099 {
100 return numberFormat;
101 }
102
103 @SideOnly(Side.CLIENT)
104
105 static DecimalFormat getDecimalFormat()
106 {
107 return decimalFormat;
108 }
109 }