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