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 WorldType[] var1 = worldTypes;
141 int var2 = var1.length;
142
143 for (int var3 = 0; var3 < var2; ++var3)
144 {
145 WorldType var4 = var1[var3];
146
147 if (var4 != null && var4.worldType.equalsIgnoreCase(par0Str))
148 {
149 return var4;
150 }
151 }
152
153 return null;
154 }
155
156 public int func_82747_f()
157 {
158 return this.worldTypeId;
159 }
160
161 public WorldChunkManager getChunkManager(World world)
162 {
163 if (this == FLAT)
164 {
165 FlatGeneratorInfo var1 = FlatGeneratorInfo.func_82651_a(world.getWorldInfo().func_82571_y());
166 return new WorldChunkManagerHell(BiomeGenBase.biomeList[var1.getBiome()], 0.5F, 0.5F);
167 }
168 else
169 {
170 return new WorldChunkManager(world);
171 }
172 }
173
174 public IChunkProvider getChunkGenerator(World world, String generatorOptions)
175 {
176 return (this == FLAT ? new ChunkProviderFlat(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled(), generatorOptions) : new ChunkProviderGenerate(world, world.getSeed(), world.getWorldInfo().isMapFeaturesEnabled()));
177 }
178
179 public int getMinimumSpawnHeight(World world)
180 {
181 return this == FLAT ? 4 : 64;
182 }
183
184 public double getHorizon(World world)
185 {
186 return this == FLAT ? 0.0D : 63.0D;
187 }
188
189 public boolean hasVoidParticles(boolean var1)
190 {
191 return this != FLAT && !var1;
192 }
193
194 public double voidFadeMagnitude()
195 {
196 return this == FLAT ? 1.0D : 0.03125D;
197 }
198
199 public BiomeGenBase[] getBiomesForWorldType() {
200 return biomesForWorldType;
201 }
202
203 public void addNewBiome(BiomeGenBase biome)
204 {
205 Set<BiomeGenBase> newBiomesForWorld = Sets.newLinkedHashSet(Arrays.asList(biomesForWorldType));
206 newBiomesForWorld.add(biome);
207 biomesForWorldType = newBiomesForWorld.toArray(new BiomeGenBase[0]);
208 }
209
210 public void removeBiome(BiomeGenBase biome)
211 {
212 Set<BiomeGenBase> newBiomesForWorld = Sets.newLinkedHashSet(Arrays.asList(biomesForWorldType));
213 newBiomesForWorld.remove(biome);
214 biomesForWorldType = newBiomesForWorld.toArray(new BiomeGenBase[0]);
215 }
216
217 public boolean handleSlimeSpawnReduction(Random random, World world)
218 {
219 return this == FLAT ? random.nextInt(4) != 1 : false;
220 }
221
222 /**
223 * Called when 'Create New World' button is pressed before starting game
224 */
225 public void onGUICreateWorldPress() { }
226
227 /**
228 * Gets the spawn fuzz for players who join the world.
229 * Useful for void world types.
230 * @return Fuzz for entity initial spawn in blocks.
231 */
232 public int getSpawnFuzz()
233 {
234 return 20;
235 }
236 }