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