001 package net.minecraft.src; 002 003 import java.util.Arrays; 004 import java.util.Random; 005 import java.util.Set; 006 007 import com.google.common.collect.ObjectArrays; 008 import com.google.common.collect.Sets; 009 010 import cpw.mods.fml.common.Side; 011 import cpw.mods.fml.common.asm.SideOnly; 012 013 public class WorldType 014 { 015 public static final BiomeGenBase[] base11Biomes = new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.forest, BiomeGenBase.extremeHills, BiomeGenBase.swampland, BiomeGenBase.plains, BiomeGenBase.taiga}; 016 public static final BiomeGenBase[] base12Biomes = ObjectArrays.concat(base11Biomes, BiomeGenBase.jungle); 017 018 /** List of world types. */ 019 public static final WorldType[] worldTypes = new WorldType[16]; 020 021 /** Default world type. */ 022 public static final WorldType DEFAULT = (new WorldType(0, "default", 1)).setVersioned(); 023 024 /** Flat world type. */ 025 public static final WorldType FLAT = new WorldType(1, "flat"); 026 027 /** Large Biome world Type. */ 028 public static final WorldType LARGE_BIOMES = new WorldType(2, "largeBiomes"); 029 030 /** Default (1.1) world type. */ 031 public static final WorldType DEFAULT_1_1 = (new WorldType(8, "default_1_1", 0)).setCanBeCreated(false); 032 033 /** ID for this world type. */ 034 private final int worldTypeId; 035 036 /** 'default' or 'flat' */ 037 private final String worldType; 038 039 /** The int version of the ChunkProvider that generated this world. */ 040 private final int generatorVersion; 041 042 /** 043 * Whether this world type can be generated. Normally true; set to false for out-of-date generator versions. 044 */ 045 private boolean canBeCreated; 046 047 /** Whether this WorldType has a version or not. */ 048 private boolean isWorldTypeVersioned; 049 050 protected BiomeGenBase[] biomesForWorldType; 051 052 public WorldType(int par1, String par2Str) 053 { 054 this(par1, par2Str, 0); 055 } 056 057 public WorldType(int par1, String par2Str, int par3) 058 { 059 this.worldType = par2Str; 060 this.generatorVersion = par3; 061 this.canBeCreated = true; 062 this.worldTypeId = par1; 063 worldTypes[par1] = this; 064 switch (par1) 065 { 066 case 8: 067 biomesForWorldType = base11Biomes; 068 break; 069 default: 070 biomesForWorldType = base12Biomes; 071 } 072 } 073 074 public String getWorldTypeName() 075 { 076 return this.worldType; 077 } 078 079 @SideOnly(Side.CLIENT) 080 081 /** 082 * Gets the translation key for the name of this world type. 083 */ 084 public String getTranslateName() 085 { 086 return "generator." + this.worldType; 087 } 088 089 /** 090 * Returns generatorVersion. 091 */ 092 public int getGeneratorVersion() 093 { 094 return this.generatorVersion; 095 } 096 097 public WorldType getWorldTypeForGeneratorVersion(int par1) 098 { 099 return this == DEFAULT && par1 == 0 ? DEFAULT_1_1 : this; 100 } 101 102 /** 103 * Sets canBeCreated to the provided value, and returns this. 104 */ 105 private WorldType setCanBeCreated(boolean par1) 106 { 107 this.canBeCreated = par1; 108 return this; 109 } 110 111 @SideOnly(Side.CLIENT) 112 113 /** 114 * Gets whether this WorldType can be used to generate a new world. 115 */ 116 public boolean getCanBeCreated() 117 { 118 return this.canBeCreated; 119 } 120 121 /** 122 * Flags this world type as having an associated version. 123 */ 124 private WorldType setVersioned() 125 { 126 this.isWorldTypeVersioned = true; 127 return this; 128 } 129 130 /** 131 * Returns true if this world Type has a version associated with it. 132 */ 133 public boolean isVersioned() 134 { 135 return this.isWorldTypeVersioned; 136 } 137 138 public static WorldType parseWorldType(String par0Str) 139 { 140 for (int var1 = 0; var1 < worldTypes.length; ++var1) 141 { 142 if (worldTypes[var1] != null && worldTypes[var1].worldType.equalsIgnoreCase(par0Str)) 143 { 144 return worldTypes[var1]; 145 } 146 } 147 148 return null; 149 } 150 151 public int func_82747_f() 152 { 153 return this.worldTypeId; 154 } 155 156 public WorldChunkManager getChunkManager(World world) 157 { 158 if (this == FLAT) 159 { 160 FlatGeneratorInfo var1 = FlatGeneratorInfo.createFlatGeneratorFromString(world.getWorldInfo().func_82571_y()); 161 return new WorldChunkManagerHell(BiomeGenBase.biomeList[var1.getBiome()], 0.5F, 0.5F); 162 } 163 else 164 { 165 return new WorldChunkManager(world); 166 } 167 } 168 169 public IChunkProvider getChunkGenerator(World world, String generatorOptions) 170 { 171 return (this == FLAT ? new ChunkProviderFlat(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled(), generatorOptions) : new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled())); 172 } 173 174 public int getMinimumSpawnHeight(World world) 175 { 176 return this == FLAT ? 4 : 64; 177 } 178 179 public double getHorizon(World world) 180 { 181 return this == FLAT ? 0.0D : 63.0D; 182 } 183 184 public boolean hasVoidParticles(boolean var1) 185 { 186 return this != FLAT && !var1; 187 } 188 189 public double voidFadeMagnitude() 190 { 191 return this == FLAT ? 1.0D : 0.03125D; 192 } 193 194 public BiomeGenBase[] getBiomesForWorldType() { 195 return biomesForWorldType; 196 } 197 198 public void addNewBiome(BiomeGenBase biome) 199 { 200 Set<BiomeGenBase> newBiomesForWorld = Sets.newLinkedHashSet(Arrays.asList(biomesForWorldType)); 201 newBiomesForWorld.add(biome); 202 biomesForWorldType = newBiomesForWorld.toArray(new BiomeGenBase[0]); 203 } 204 205 public void removeBiome(BiomeGenBase biome) 206 { 207 Set<BiomeGenBase> newBiomesForWorld = Sets.newLinkedHashSet(Arrays.asList(biomesForWorldType)); 208 newBiomesForWorld.remove(biome); 209 biomesForWorldType = newBiomesForWorld.toArray(new BiomeGenBase[0]); 210 } 211 212 public boolean handleSlimeSpawnReduction(Random random, World world) 213 { 214 return this == FLAT ? random.nextInt(4) != 1 : false; 215 } 216 217 /** 218 * Called when 'Create New World' button is pressed before starting game 219 */ 220 public void onGUICreateWorldPress() { } 221 222 /** 223 * Gets the spawn fuzz for players who join the world. 224 * Useful for void world types. 225 * @return Fuzz for entity initial spawn in blocks. 226 */ 227 public int getSpawnFuzz() 228 { 229 return 20; 230 } 231 }