001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    public enum EnumGameType
007    {
008        NOT_SET(-1, ""),
009        SURVIVAL(0, "survival"),
010        CREATIVE(1, "creative"),
011        ADVENTURE(2, "adventure");
012        int id;
013        String name;
014    
015        private EnumGameType(int par3, String par4Str)
016        {
017            this.id = par3;
018            this.name = par4Str;
019        }
020    
021        /**
022         * Returns the ID of this game type
023         */
024        public int getID()
025        {
026            return this.id;
027        }
028    
029        /**
030         * Returns the name of this game type
031         */
032        public String getName()
033        {
034            return this.name;
035        }
036    
037        /**
038         * Configures the player capabilities based on the game type
039         */
040        public void configurePlayerCapabilities(PlayerCapabilities par1PlayerCapabilities)
041        {
042            if (this == CREATIVE)
043            {
044                par1PlayerCapabilities.allowFlying = true;
045                par1PlayerCapabilities.isCreativeMode = true;
046                par1PlayerCapabilities.disableDamage = true;
047            }
048            else
049            {
050                par1PlayerCapabilities.allowFlying = false;
051                par1PlayerCapabilities.isCreativeMode = false;
052                par1PlayerCapabilities.disableDamage = false;
053                par1PlayerCapabilities.isFlying = false;
054            }
055    
056            par1PlayerCapabilities.allowEdit = !this.isAdventure();
057        }
058    
059        /**
060         * Returns true if this is the ADVENTURE game type
061         */
062        public boolean isAdventure()
063        {
064            return this == ADVENTURE;
065        }
066    
067        /**
068         * Returns true if this is the CREATIVE game type
069         */
070        public boolean isCreative()
071        {
072            return this == CREATIVE;
073        }
074    
075        @SideOnly(Side.CLIENT)
076        public boolean func_77144_e()
077        {
078            return this == SURVIVAL || this == ADVENTURE;
079        }
080    
081        /**
082         * Returns the game type with the specified ID, or SURVIVAL if none found. Args: id
083         */
084        public static EnumGameType getByID(int par0)
085        {
086            EnumGameType[] var1 = values();
087            int var2 = var1.length;
088    
089            for (int var3 = 0; var3 < var2; ++var3)
090            {
091                EnumGameType var4 = var1[var3];
092    
093                if (var4.id == par0)
094                {
095                    return var4;
096                }
097            }
098    
099            return SURVIVAL;
100        }
101    
102        @SideOnly(Side.CLIENT)
103    
104        /**
105         * Returns the game type with the specified name, or SURVIVAL if none found. This is case sensitive. Args: name
106         */
107        public static EnumGameType getByName(String par0Str)
108        {
109            EnumGameType[] var1 = values();
110            int var2 = var1.length;
111    
112            for (int var3 = 0; var3 < var2; ++var3)
113            {
114                EnumGameType var4 = var1[var3];
115    
116                if (var4.name.equals(par0Str))
117                {
118                    return var4;
119                }
120            }
121    
122            return SURVIVAL;
123        }
124    }