Skip to content

Instantly share code, notes, and snippets.

@UgurkanTech
Created February 22, 2024 02:42
Show Gist options
  • Save UgurkanTech/4d4f7cbdde601ac5ba618a8d3d8a631d to your computer and use it in GitHub Desktop.
Save UgurkanTech/4d4f7cbdde601ac5ba618a8d3d8a631d to your computer and use it in GitHub Desktop.
A low level block struct.
public struct Block
{
uint data; //8 bytes
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Block(BlockType id, ushort metaData, bool isOpaque)
{
data = (uint)((ushort)id << 16) | (uint)(metaData << 1) | (uint)(isOpaque ? 0x1 : 0x0);
}
//Id 0-65535
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BlockType GetID()
{
return (BlockType)((ushort)(data >> 16));
}
//Meta 0-32766
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort GetMetaData()
{
return (ushort)((data & 0x0000FFFF) >> 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool GetIsOpaque()
{
return data % 2 == 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment