using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MinecraftClient.Mapping { /// /// Represents a Minecraft Block /// public struct Block { /// /// Storage for block ID and metadata /// private ushort blockIdAndMeta; /// /// Id of the block /// public short BlockId { get { return (short)(blockIdAndMeta >> 4); } set { blockIdAndMeta = (ushort)(value << 4 | BlockMeta); } } /// /// Metadata of the block /// public byte BlockMeta { get { return (byte)(blockIdAndMeta & 0x0F); } set { blockIdAndMeta = (ushort)((blockIdAndMeta & ~0x0F) | (value & 0x0F)); } } /// /// Material of the block /// public Material Type { get { return (Material)BlockId; } } /// /// Get a block of the specified type and metadata /// /// Block type /// Block metadata public Block(short type, byte metadata = 0) { this.blockIdAndMeta = 0; this.BlockId = type; this.BlockMeta = metadata; } /// /// Get a block of the specified type and metadata /// /// Type and metadata packed in the same value public Block(ushort typeAndMeta) { this.blockIdAndMeta = typeAndMeta; } /// /// Get a block of the specified type and metadata /// /// Block type public Block(Material type, byte metadata = 0) : this((short)type, metadata) { } /// /// String representation of the block /// public override string ToString() { return BlockId.ToString() + (BlockMeta != 0 ? ":" + BlockMeta.ToString() : ""); } } }