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