Minecraft-Console-Client/MinecraftClient/Mapping/ChunkColumn.cs

64 lines
1.6 KiB
C#
Raw Normal View History

using System;
namespace MinecraftClient.Mapping
{
/// <summary>
/// Represent a column of chunks of terrain in a Minecraft world
/// </summary>
public class ChunkColumn
{
public int ColumnSize;
2022-07-25 03:19:24 +08:00
public bool FullyLoaded = false;
/// <summary>
/// Blocks contained into the chunk
/// </summary>
2022-08-25 10:40:55 +08:00
private readonly Chunk?[] chunks;
/// <summary>
/// Create a new ChunkColumn
/// </summary>
public ChunkColumn(int size = 16)
{
ColumnSize = size;
2022-08-25 10:40:55 +08:00
chunks = new Chunk?[size];
}
/// <summary>
/// Get or set the specified chunk column
/// </summary>
/// <param name="chunkX">ChunkColumn X</param>
/// <param name="chunkY">ChunkColumn Y</param>
/// <returns>chunk at the given location</returns>
2022-08-25 10:40:55 +08:00
public Chunk? this[int chunkY]
{
get
{
return chunks[chunkY];
}
set
{
chunks[chunkY] = value;
}
}
/// <summary>
/// Get chunk at the specified location
/// </summary>
/// <param name="location">Location, a modulo will be applied</param>
/// <returns>The chunk, or null if not loaded</returns>
public Chunk? GetChunk(Location location)
{
try
{
return this[location.ChunkY];
}
catch (IndexOutOfRangeException)
{
return null;
}
}
}
}