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