Skip to content

Instantly share code, notes, and snippets.

@Jaezmien
Last active January 7, 2023 03:40
Show Gist options
  • Save Jaezmien/abd53e4ca78af944baa91af72cd35133 to your computer and use it in GitHub Desktop.
Save Jaezmien/abd53e4ca78af944baa91af72cd35133 to your computer and use it in GitHub Desktop.
Tiny version of BlockPos.jar from Minecraft for handling different formats (Vector3 & Long)
using System.Numerics;
namespace Minecraft
{
class TinyBlockPos
{
private static long X_MASK = (1L << 26) - 1L;
private static long Y_MASK = (1L << 12) - 1L;
private static long Z_MASK = (1L << 26) - 1L;
private Vector3 position;
public TinyBlockPos(int x, int y, int z) { this.position = new Vector3(x, y, z); }
public TinyBlockPos(long position)
{
int x = (int)(position << 0 >> 38);
int y = (int)(position << 52 >> 52);
int z = (int)(position << 26 >> 38);
this.position = new Vector3(x, y, z);
}
public long getLong
{
get
{
long i = 0L | ((long)this.position.X & X_MASK) << 38;
i = i | ((long)this.position.Y & Y_MASK) << 0;
return i | ((long)this.position.Z & Z_MASK) << 12;
}
}
public Vector3 getVector { get { return position; } }
public string getReadableVector
{
get { return $"X:{ this.position.X } Y:{ this.position.Y } Z:{ this.position.Z }"; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment