    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        @SideOnly(Side.CLIENT)
    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.func_82651_a(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    }