Add: Helper methods for obtaining X and Z coordinates of chunk given a block's X and Z world coordinates.
This commit is contained in:
parent
d4f93f8266
commit
cfa49b50a4
@ -174,6 +174,16 @@ namespace TrueCraft.Core
|
||||
return ChunkZ * Chunk.Depth + BlockCoord;
|
||||
}
|
||||
|
||||
public static int BlockToChunkX(int BlockCoord)
|
||||
{
|
||||
return (int)Math.Floor((double)BlockCoord / Chunk.Width);
|
||||
}
|
||||
|
||||
public static int BlockToChunkZ(int BlockCoord)
|
||||
{
|
||||
return (int)Math.Floor((double)BlockCoord / Chunk.Depth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating the most extreme value of the
|
||||
/// provided Vector.
|
||||
|
@ -299,8 +299,8 @@ namespace TrueCraft.Core.World
|
||||
if (coordinates.Y < 0 || coordinates.Y >= Chunk.Height)
|
||||
throw new ArgumentOutOfRangeException("coordinates", "Coordinates are out of range");
|
||||
|
||||
var chunkX = (int)Math.Floor((double)coordinates.X / Chunk.Width);
|
||||
var chunkZ = (int)Math.Floor((double)coordinates.Z / Chunk.Depth);
|
||||
var chunkX = MathHelper.BlockToChunkX(coordinates.X);
|
||||
var chunkZ = MathHelper.BlockToChunkZ(coordinates.Z);
|
||||
|
||||
chunk = GetChunk(new Coordinates2D(chunkX, chunkZ));
|
||||
return new Coordinates3D(
|
||||
|
Loading…
x
Reference in New Issue
Block a user