2015-11-30 15:30:49 +01:00
|
|
|
|
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>
|
2015-12-09 23:04:00 +01:00
|
|
|
|
/// Material of the block
|
2015-11-30 15:30:49 +01:00
|
|
|
|
/// </summary>
|
2015-12-09 23:04:00 +01:00
|
|
|
|
public Material Type
|
2015-11-30 15:30:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2015-12-09 23:04:00 +01:00
|
|
|
|
return (Material)BlockId;
|
2015-11-30 15:30:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2015-12-09 23:04:00 +01:00
|
|
|
|
/// <param name="typeAndMeta">Type and metadata packed in the same value</param>
|
2015-11-30 15:30:49 +01:00
|
|
|
|
public Block(ushort typeAndMeta)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.blockIdAndMeta = typeAndMeta;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-12-09 23:04:00 +01:00
|
|
|
|
/// Get a block of the specified type and metadata
|
2015-11-30 15:30:49 +01:00
|
|
|
|
/// </summary>
|
2015-12-09 23:04:00 +01:00
|
|
|
|
/// <param name="type">Block type</param>
|
|
|
|
|
|
public Block(Material type, byte metadata = 0)
|
|
|
|
|
|
: this((short)type, metadata) { }
|
2015-11-30 15:30:49 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// String representation of the block
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
return BlockId.ToString() + (BlockMeta != 0 ? ":" + BlockMeta.ToString() : "");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|