/// <summary> /// Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the /// specified chunk from the map seed and chunk seed /// </summary> public virtual Chunk ProvideChunk(int par1, int par2) { if (par1 == LastQueriedChunkXPos && par2 == LastQueriedChunkZPos && LastQueriedChunk != null) { return(LastQueriedChunk); } if (!WorldObj.FindingSpawnPoint && !CanChunkExist(par1, par2)) { return(BlankChunk); } int i = par1 & 0x1f; int j = par2 & 0x1f; int k = i + j * 32; if (!ChunkExists(par1, par2)) { if (Chunks[k] != null) { Chunks[k].OnChunkUnload(); SaveChunk(Chunks[k]); SaveExtraChunkData(Chunks[k]); } Chunk chunk = Func_542_c(par1, par2); if (chunk == null) { if (ChunkProvider == null) { chunk = BlankChunk; } else { chunk = ChunkProvider.ProvideChunk(par1, par2); chunk.RemoveUnknownBlocks(); } } Chunks[k] = chunk; chunk.Func_4143_d(); if (Chunks[k] != null) { Chunks[k].OnChunkLoad(); } Chunks[k].PopulateChunk(this, this, par1, par2); } LastQueriedChunkXPos = par1; LastQueriedChunkZPos = par2; LastQueriedChunk = Chunks[k]; return(Chunks[k]); }
public virtual void PopulateChunk(IChunkProvider par1IChunkProvider, IChunkProvider par2IChunkProvider, int par3, int par4) { if (!IsTerrainPopulated && par1IChunkProvider.ChunkExists(par3 + 1, par4 + 1) && par1IChunkProvider.ChunkExists(par3, par4 + 1) && par1IChunkProvider.ChunkExists(par3 + 1, par4)) { par1IChunkProvider.Populate(par2IChunkProvider, par3, par4); } if (par1IChunkProvider.ChunkExists(par3 - 1, par4) && !par1IChunkProvider.ProvideChunk(par3 - 1, par4).IsTerrainPopulated&& par1IChunkProvider.ChunkExists(par3 - 1, par4 + 1) && par1IChunkProvider.ChunkExists(par3, par4 + 1) && par1IChunkProvider.ChunkExists(par3 - 1, par4 + 1)) { par1IChunkProvider.Populate(par2IChunkProvider, par3 - 1, par4); } if (par1IChunkProvider.ChunkExists(par3, par4 - 1) && !par1IChunkProvider.ProvideChunk(par3, par4 - 1).IsTerrainPopulated&& par1IChunkProvider.ChunkExists(par3 + 1, par4 - 1) && par1IChunkProvider.ChunkExists(par3 + 1, par4 - 1) && par1IChunkProvider.ChunkExists(par3 + 1, par4)) { par1IChunkProvider.Populate(par2IChunkProvider, par3, par4 - 1); } if (par1IChunkProvider.ChunkExists(par3 - 1, par4 - 1) && !par1IChunkProvider.ProvideChunk(par3 - 1, par4 - 1).IsTerrainPopulated&& par1IChunkProvider.ChunkExists(par3, par4 - 1) && par1IChunkProvider.ChunkExists(par3 - 1, par4)) { par1IChunkProvider.Populate(par2IChunkProvider, par3 - 1, par4 - 1); } }
///<summary> /// loads or generates the chunk at the chunk location specified ///</summary> public Chunk LoadChunk(int par1, int par2) { long l = ChunkCoordIntPair.ChunkXZ2Int(par1, par2); droppedChunksSet.Remove(l); Chunk chunk = (Chunk)chunkMap.GetValueByKey(l); if (chunk == null) { int i = 0x1c9c3c; if (par1 < -i || par2 < -i || par1 >= i || par2 >= i) { return(emptyChunk); } chunk = LoadChunkFromFile(par1, par2); if (chunk == null) { if (chunkProvider == null) { chunk = emptyChunk; } else { chunk = chunkProvider.ProvideChunk(par1, par2); } } chunkMap.Add(l, chunk); chunkList.Add(chunk); if (chunk != null) { chunk.Func_4143_d(); chunk.OnChunkLoad(); } chunk.PopulateChunk(this, this, par1, par2); } return(chunk); }