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:
ORelio 2015-11-30 15:30:49 +01:00
parent 2e4544fc5a
commit cb00c28b6e
10 changed files with 661 additions and 91 deletions

View file

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Mapping
{
/// <summary>
/// Represents a Minecraft Block
/// </summary>
public struct Block
{
/// <summary>
/// Storage for block ID and metadata
/// </summary>
private ushort blockIdAndMeta;
/// <summary>
/// Id of the block
/// </summary>
public short BlockId
{
get
{
return (short)(blockIdAndMeta >> 4);
}
set
{
blockIdAndMeta = (ushort)(value << 4 | BlockMeta);
}
}
/// <summary>
/// Metadata of the block
/// </summary>
public byte BlockMeta
{
get
{
return (byte)(blockIdAndMeta & 0x0F);
}
set
{
blockIdAndMeta = (ushort)((blockIdAndMeta & ~0x0F) | (value & 0x0F));
}
}
/// <summary>
/// Check if the block can be passed through or not
/// </summary>
public bool Solid
{
get
{
return BlockId != 0;
}
}
/// <summary>
/// Get a block of the specified type and metadata
/// </summary>
/// <param name="type">Block type</param>
/// <param name="metadata">Block metadata</param>
public Block(short type, byte metadata = 0)
{
this.blockIdAndMeta = 0;
this.BlockId = type;
this.BlockMeta = metadata;
}
/// <summary>
/// Get a block of the specified type and metadata
/// </summary>
/// <param name="typeAndMeta"></param>
public Block(ushort typeAndMeta)
{
this.blockIdAndMeta = typeAndMeta;
}
/// <summary>
/// Represents an empty block
/// </summary>
public static Block Air
{
get
{
return new Block(0);
}
}
/// <summary>
/// String representation of the block
/// </summary>
public override string ToString()
{
return BlockId.ToString() + (BlockMeta != 0 ? ":" + BlockMeta.ToString() : "");
}
}
}