using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace MinecraftClient.Mapping { /// /// Represent a column of chunks of terrain in a Minecraft world /// public class ChunkColumn { public const int ColumnSize = 16; /// /// Blocks contained into the chunk /// private readonly Chunk[] chunks = new Chunk[ColumnSize]; /// /// Lock for thread safety /// private readonly ReaderWriterLockSlim chunkLock = new ReaderWriterLockSlim(); /// /// Get or set the specified chunk column /// /// ChunkColumn X /// ChunkColumn Y /// chunk at the given location public Chunk this[int chunkY] { get { chunkLock.EnterReadLock(); try { return chunks[chunkY]; } finally { chunkLock.ExitReadLock(); } } set { chunkLock.EnterWriteLock(); try { chunks[chunkY] = value; } finally { chunkLock.ExitWriteLock(); } } } /// /// Get chunk at the specified location /// /// Location, a modulo will be applied /// The chunk, or null if not loaded public Chunk GetChunk(Location location) { try { return this[location.ChunkY]; } catch (IndexOutOfRangeException) { return null; } } } }