001    package net.minecraft.src;
002    
003    import java.util.List;
004    import java.util.Random;
005    
006    public class ChunkProviderFlat implements IChunkProvider
007    {
008        private World worldObj;
009        private Random random;
010        private final boolean useStructures;
011        private MapGenVillage villageGen = new MapGenVillage(1);
012    
013        public ChunkProviderFlat(World par1World, long par2, boolean par4)
014        {
015            this.worldObj = par1World;
016            this.useStructures = par4;
017            this.random = new Random(par2);
018        }
019    
020        private void generate(byte[] par1ArrayOfByte)
021        {
022            int var2 = par1ArrayOfByte.length / 256;
023    
024            for (int var3 = 0; var3 < 16; ++var3)
025            {
026                for (int var4 = 0; var4 < 16; ++var4)
027                {
028                    for (int var5 = 0; var5 < var2; ++var5)
029                    {
030                        int var6 = 0;
031    
032                        if (var5 == 0)
033                        {
034                            var6 = Block.bedrock.blockID;
035                        }
036                        else if (var5 <= 2)
037                        {
038                            var6 = Block.dirt.blockID;
039                        }
040                        else if (var5 == 3)
041                        {
042                            var6 = Block.grass.blockID;
043                        }
044    
045                        par1ArrayOfByte[var3 << 11 | var4 << 7 | var5] = (byte)var6;
046                    }
047                }
048            }
049        }
050    
051        /**
052         * loads or generates the chunk at the chunk location specified
053         */
054        public Chunk loadChunk(int par1, int par2)
055        {
056            return this.provideChunk(par1, par2);
057        }
058    
059        /**
060         * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
061         * specified chunk from the map seed and chunk seed
062         */
063        public Chunk provideChunk(int par1, int par2)
064        {
065            byte[] var3 = new byte[32768];
066            this.generate(var3);
067            Chunk var4 = new Chunk(this.worldObj, var3, par1, par2);
068    
069            if (this.useStructures)
070            {
071                this.villageGen.generate(this, this.worldObj, par1, par2, var3);
072            }
073    
074            BiomeGenBase[] var5 = this.worldObj.getWorldChunkManager().loadBlockGeneratorData((BiomeGenBase[])null, par1 * 16, par2 * 16, 16, 16);
075            byte[] var6 = var4.getBiomeArray();
076    
077            for (int var7 = 0; var7 < var6.length; ++var7)
078            {
079                var6[var7] = (byte)var5[var7].biomeID;
080            }
081    
082            var4.generateSkylightMap();
083            return var4;
084        }
085    
086        /**
087         * Checks to see if a chunk exists at x, y
088         */
089        public boolean chunkExists(int par1, int par2)
090        {
091            return true;
092        }
093    
094        /**
095         * Populates chunk with ores etc etc
096         */
097        public void populate(IChunkProvider par1IChunkProvider, int par2, int par3)
098        {
099            this.random.setSeed(this.worldObj.getSeed());
100            long var4 = this.random.nextLong() / 2L * 2L + 1L;
101            long var6 = this.random.nextLong() / 2L * 2L + 1L;
102            this.random.setSeed((long)par2 * var4 + (long)par3 * var6 ^ this.worldObj.getSeed());
103    
104            if (this.useStructures)
105            {
106                this.villageGen.generateStructuresInChunk(this.worldObj, this.random, par2, par3);
107            }
108        }
109    
110        /**
111         * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
112         * Return true if all chunks have been saved.
113         */
114        public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate)
115        {
116            return true;
117        }
118    
119        /**
120         * Unloads the 100 oldest chunks from memory, due to a bug with chunkSet.add() never being called it thinks the list
121         * is always empty and will not remove any chunks.
122         */
123        public boolean unload100OldestChunks()
124        {
125            return false;
126        }
127    
128        /**
129         * Returns if the IChunkProvider supports saving.
130         */
131        public boolean canSave()
132        {
133            return true;
134        }
135    
136        /**
137         * Converts the instance data to a readable string.
138         */
139        public String makeString()
140        {
141            return "FlatLevelSource";
142        }
143    
144        /**
145         * Returns a list of creatures of the specified type that can spawn at the given location.
146         */
147        public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
148        {
149            BiomeGenBase var5 = this.worldObj.getBiomeGenForCoords(par2, par4);
150            return var5 == null ? null : var5.getSpawnableList(par1EnumCreatureType);
151        }
152    
153        /**
154         * Returns the location of the closest structure of the specified type. If not found returns null.
155         */
156        public ChunkPosition findClosestStructure(World par1World, String par2Str, int par3, int par4, int par5)
157        {
158            return null;
159        }
160    
161        public int getLoadedChunkCount()
162        {
163            return 0;
164        }
165    }