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