mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add world handling (and fall to ground)
- World is now properly parsed and stored from chunk data - Block changes are also handled and world updated accordingly - Added ground checking, the player will move down to reach the ground - Performance tweaking in Protocol18, using lists instead of arrays - Fix player look not properly skipped causing invalid location after teleport
This commit is contained in:
parent
2e4544fc5a
commit
cb00c28b6e
10 changed files with 661 additions and 91 deletions
63
MinecraftClient/Mapping/Chunk.cs
Normal file
63
MinecraftClient/Mapping/Chunk.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Mapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent a chunk of terrain in a Minecraft world
|
||||
/// </summary>
|
||||
public class Chunk
|
||||
{
|
||||
public const int SizeX = 16;
|
||||
public const int SizeY = 16;
|
||||
public const int SizeZ = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Blocks contained into the chunk
|
||||
/// </summary>
|
||||
private readonly Block[,,] blocks = new Block[SizeX, SizeY, SizeZ];
|
||||
|
||||
/// <summary>
|
||||
/// Read, or set the specified block
|
||||
/// </summary>
|
||||
/// <param name="blockX">Block X</param>
|
||||
/// <param name="blockY">Block Y</param>
|
||||
/// <param name="blockZ">Block Z</param>
|
||||
/// <returns>chunk at the given location</returns>
|
||||
public Block this[int blockX, int blockY, int blockZ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blockX < 0 || blockX >= SizeX)
|
||||
throw new ArgumentOutOfRangeException("blockX", "Must be between 0 and " + (SizeX - 1) + " (inclusive)");
|
||||
if (blockY < 0 || blockY >= SizeY)
|
||||
throw new ArgumentOutOfRangeException("blockY", "Must be between 0 and " + (SizeY - 1) + " (inclusive)");
|
||||
if (blockZ < 0 || blockZ >= SizeZ)
|
||||
throw new ArgumentOutOfRangeException("blockZ", "Must be between 0 and " + (SizeZ - 1) + " (inclusive)");
|
||||
return blocks[blockX, blockY, blockZ];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (blockX < 0 || blockX >= SizeX)
|
||||
throw new ArgumentOutOfRangeException("blockX", "Must be between 0 and " + (SizeX - 1) + " (inclusive)");
|
||||
if (blockY < 0 || blockY >= SizeY)
|
||||
throw new ArgumentOutOfRangeException("blockY", "Must be between 0 and " + (SizeY - 1) + " (inclusive)");
|
||||
if (blockZ < 0 || blockZ >= SizeZ)
|
||||
throw new ArgumentOutOfRangeException("blockZ", "Must be between 0 and " + (SizeZ - 1) + " (inclusive)");
|
||||
blocks[blockX, blockY, blockZ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get block at the specified location
|
||||
/// </summary>
|
||||
/// <param name="location">Location, a modulo will be applied</param>
|
||||
/// <returns>The block</returns>
|
||||
public Block GetBlock(Location location)
|
||||
{
|
||||
return this[((int)location.X) % Chunk.SizeX, ((int)location.Y) % Chunk.SizeY, ((int)location.Z) % Chunk.SizeZ];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue