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