Last active
January 7, 2023 03:40
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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