001 package net.minecraft.world; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import net.minecraft.entity.player.PlayerCapabilities; 006 007 public 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[] var1 = values(); 092 int var2 = var1.length; 093 094 for (int var3 = 0; var3 < var2; ++var3) 095 { 096 EnumGameType var4 = var1[var3]; 097 098 if (var4.id == par0) 099 { 100 return var4; 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[] var1 = values(); 115 int var2 = var1.length; 116 117 for (int var3 = 0; var3 < var2; ++var3) 118 { 119 EnumGameType var4 = var1[var3]; 120 121 if (var4.name.equals(par0Str)) 122 { 123 return var4; 124 } 125 } 126 127 return SURVIVAL; 128 } 129 }