001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.util.ArrayList;
006    import java.util.List;
007    
008    @SideOnly(Side.CLIENT)
009    public class ChunkProviderClient implements IChunkProvider
010    {
011        /**
012         * The completely empty chunk used by ChunkProviderClient when chunkMapping doesn't contain the requested
013         * coordinates.
014         */
015        private Chunk blankChunk;
016    
017        /**
018         * The mapping between ChunkCoordinates and Chunks that ChunkProviderClient maintains.
019         */
020        private LongHashMap chunkMapping = new LongHashMap();
021    
022        /**
023         * This may have been intended to be an iterable version of all currently loaded chunks (MultiplayerChunkCache),
024         * with identical contents to chunkMapping's values. However it is never actually added to.
025         */
026        private List chunkListing = new ArrayList();
027    
028        /** Reference to the World object. */
029        private World worldObj;
030    
031        public ChunkProviderClient(World par1World)
032        {
033            this.blankChunk = new EmptyChunk(par1World, 0, 0);
034            this.worldObj = par1World;
035        }
036    
037        /**
038         * Checks to see if a chunk exists at x, y
039         */
040        public boolean chunkExists(int par1, int par2)
041        {
042            return true;
043        }
044    
045        /**
046         * Unload chunk from ChunkProviderClient's hashmap. Called in response to a Packet50PreChunk with its mode field set
047         * to false
048         */
049        public void unloadChunk(int par1, int par2)
050        {
051            Chunk var3 = this.provideChunk(par1, par2);
052    
053            if (!var3.isEmpty())
054            {
055                var3.onChunkUnload();
056            }
057    
058            this.chunkMapping.remove(ChunkCoordIntPair.chunkXZ2Int(par1, par2));
059            this.chunkListing.remove(var3);
060        }
061    
062        /**
063         * loads or generates the chunk at the chunk location specified
064         */
065        public Chunk loadChunk(int par1, int par2)
066        {
067            Chunk var3 = new Chunk(this.worldObj, par1, par2);
068            this.chunkMapping.add(ChunkCoordIntPair.chunkXZ2Int(par1, par2), var3);
069            var3.isChunkLoaded = true;
070            return var3;
071        }
072    
073        /**
074         * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
075         * specified chunk from the map seed and chunk seed
076         */
077        public Chunk provideChunk(int par1, int par2)
078        {
079            Chunk var3 = (Chunk)this.chunkMapping.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(par1, par2));
080            return var3 == null ? this.blankChunk : var3;
081        }
082    
083        /**
084         * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
085         * Return true if all chunks have been saved.
086         */
087        public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate)
088        {
089            return true;
090        }
091    
092        /**
093         * Unloads the 100 oldest chunks from memory, due to a bug with chunkSet.add() never being called it thinks the list
094         * is always empty and will not remove any chunks.
095         */
096        public boolean unload100OldestChunks()
097        {
098            return false;
099        }
100    
101        /**
102         * Returns if the IChunkProvider supports saving.
103         */
104        public boolean canSave()
105        {
106            return false;
107        }
108    
109        /**
110         * Populates chunk with ores etc etc
111         */
112        public void populate(IChunkProvider par1IChunkProvider, int par2, int par3) {}
113    
114        /**
115         * Converts the instance data to a readable string.
116         */
117        public String makeString()
118        {
119            return "MultiplayerChunkCache: " + this.chunkMapping.getNumHashElements();
120        }
121    
122        /**
123         * Returns a list of creatures of the specified type that can spawn at the given location.
124         */
125        public List getPossibleCreatures(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
126        {
127            return null;
128        }
129    
130        /**
131         * Returns the location of the closest structure of the specified type. If not found returns null.
132         */
133        public ChunkPosition findClosestStructure(World par1World, String par2Str, int par3, int par4, int par5)
134        {
135            return null;
136        }
137    
138        public int getLoadedChunkCount()
139        {
140            return this.chunkListing.size();
141        }
142    }