    001    package net.minecraft.src;
    002
    003    import java.util.Collection;
    004    import java.util.Iterator;
    005    import java.util.TreeMap;
    006
    007    public class GameRules
    008    {
    009        private TreeMap theGameRules = new TreeMap();
    010
    011        public GameRules()
    012        {
    013            this.addGameRule("doFireTick", "true");
    014            this.addGameRule("mobGriefing", "true");
    015            this.addGameRule("keepInventory", "false");
    016            this.addGameRule("doMobSpawning", "true");
    017            this.addGameRule("doMobLoot", "true");
    018            this.addGameRule("doTileDrops", "true");
    019            this.addGameRule("commandBlockOutput", "true");
    020        }
    021
    022        /**
    023         * Define a game rule and its default value.
    024         */
    025        public void addGameRule(String par1Str, String par2Str)
    026        {
    027            this.theGameRules.put(par1Str, new GameRuleValue(par2Str));
    028        }
    029
    030        public void func_82764_b(String par1Str, String par2Str)
    031        {
    032            GameRuleValue var3 = (GameRuleValue)this.theGameRules.get(par1Str);
    033
    034            if (var3 != null)
    035            {
    036                var3.setValue(par2Str);
    037            }
    038            else
    039            {
    040                this.addGameRule(par1Str, par2Str);
    041            }
    042        }
    043
    044        /**
    045         * Gets the string Game Rule value.
    046         */
    047        public String getGameRuleStringValue(String par1Str)
    048        {
    049            GameRuleValue var2 = (GameRuleValue)this.theGameRules.get(par1Str);
    050            return var2 != null ? var2.getGameRuleStringValue() : "";
    051        }
    052
    053        /**
    054         * Gets the boolean Game Rule value.
    055         */
    056        public boolean getGameRuleBooleanValue(String par1Str)
    057        {
    058            GameRuleValue var2 = (GameRuleValue)this.theGameRules.get(par1Str);
    059            return var2 != null ? var2.getGameRuleBooleanValue() : false;
    060        }
    061
    062        /**
    063         * Return the defined game rules as NBT.
    064         */
    065        public NBTTagCompound writeGameRulesToNBT()
    066        {
    067            NBTTagCompound var1 = new NBTTagCompound("GameRules");
    068            Iterator var2 = this.theGameRules.keySet().iterator();
    069
    070            while (var2.hasNext())
    071            {
    072                String var3 = (String)var2.next();
    073                GameRuleValue var4 = (GameRuleValue)this.theGameRules.get(var3);
    074                var1.setString(var3, var4.getGameRuleStringValue());
    075            }
    076
    077            return var1;
    078        }
    079
    080        /**
    081         * Set defined game rules from NBT.
    082         */
    083        public void readGameRulesFromNBT(NBTTagCompound par1NBTTagCompound)
    084        {
    085            Collection var2 = par1NBTTagCompound.getTags();
    086            Iterator var3 = var2.iterator();
    087
    088            while (var3.hasNext())
    089            {
    090                NBTBase var4 = (NBTBase)var3.next();
    091                String var5 = var4.getName();
    092                String var6 = par1NBTTagCompound.getString(var4.getName());
    093                this.func_82764_b(var5, var6);
    094            }
    095        }
    096
    097        /**
    098         * Return the defined game rules.
    099         */
    100        public String[] getRules()
    101        {
    102            return (String[])this.theGameRules.keySet().toArray(new String[0]);
    103        }
    104
    105        /**
    106         * Return whether the specified game rule is defined.
    107         */
    108        public boolean hasRule(String par1Str)
    109        {
    110            return this.theGameRules.containsKey(par1Str);
    111        }
    112    }