summaryrefslogtreecommitdiffstats
path: root/src/ByteBuffer.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-07-20 10:56:27 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-07-26 19:55:16 +0200
commit99f8c4434246c3483436b1abac917cf3f23ddbc2 (patch)
tree866c1ad86ac7fc8ca243f5261fca47e6f737e792 /src/ByteBuffer.cpp
parentRemove redundant ErasePowerData call (diff)
downloadcuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar.gz
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar.bz2
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar.lz
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar.xz
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.tar.zst
cuberite-99f8c4434246c3483436b1abac917cf3f23ddbc2.zip
Diffstat (limited to '')
-rw-r--r--src/ByteBuffer.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 6109afdee..f3a6e3a7d 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -472,7 +472,7 @@ bool cByteBuffer::ReadLEInt(int & a_Value)
-bool cByteBuffer::ReadPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+bool cByteBuffer::ReadXYZPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
{
CHECK_THREAD
Int64 Value;
@@ -488,7 +488,7 @@ bool cByteBuffer::ReadPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
// If the highest bit in the number's range is set, convert the number into negative:
a_BlockX = ((BlockXRaw & 0x02000000) == 0) ? static_cast<int>(BlockXRaw) : -(0x04000000 - static_cast<int>(BlockXRaw));
- a_BlockY = ((BlockYRaw & 0x0800) == 0) ? static_cast<int>(BlockYRaw) : -(0x0800 - static_cast<int>(BlockYRaw));
+ a_BlockY = ((BlockYRaw & 0x0800) == 0) ? static_cast<int>(BlockYRaw) : -(0x01000 - static_cast<int>(BlockYRaw));
a_BlockZ = ((BlockZRaw & 0x02000000) == 0) ? static_cast<int>(BlockZRaw) : -(0x04000000 - static_cast<int>(BlockZRaw));
return true;
}
@@ -497,6 +497,31 @@ bool cByteBuffer::ReadPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+bool cByteBuffer::ReadXZYPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+{
+ CHECK_THREAD
+ Int64 Value;
+ if (!ReadBEInt64(Value))
+ {
+ return false;
+ }
+
+ // Convert the 64 received bits into 3 coords:
+ UInt32 BlockXRaw = (Value >> 38) & 0x03ffffff; // Top 26 bits
+ UInt32 BlockZRaw = (Value >> 12) & 0x03ffffff; // Middle 26 bits
+ UInt32 BlockYRaw = (Value & 0x0fff); // Bottom 12 bits
+
+ // If the highest bit in the number's range is set, convert the number into negative:
+ a_BlockX = ((BlockXRaw & 0x02000000) == 0) ? static_cast<int>(BlockXRaw) : (static_cast<int>(BlockXRaw) - 0x04000000);
+ a_BlockY = ((BlockYRaw & 0x0800) == 0) ? static_cast<int>(BlockYRaw) : (static_cast<int>(BlockYRaw) - 0x01000);
+ a_BlockZ = ((BlockZRaw & 0x02000000) == 0) ? static_cast<int>(BlockZRaw) : (static_cast<int>(BlockZRaw) - 0x04000000);
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::ReadUUID(cUUID & a_Value)
{
CHECK_THREAD
@@ -718,7 +743,7 @@ bool cByteBuffer::WriteVarUTF8String(const AString & a_Value)
-bool cByteBuffer::WritePosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ)
+bool cByteBuffer::WriteXYZPosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ)
{
CHECK_THREAD
CheckValid();
@@ -733,6 +758,21 @@ bool cByteBuffer::WritePosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ
+bool cByteBuffer::WriteXZYPosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_BlockZ)
+{
+ CHECK_THREAD
+ CheckValid();
+ return WriteBEInt64(
+ (static_cast<Int64>(a_BlockX & 0x3FFFFFF) << 38) |
+ (static_cast<Int64>(a_BlockZ & 0x3FFFFFF) << 26) |
+ (static_cast<Int64>(a_BlockY & 0xFFF))
+ );
+}
+
+
+
+
+
bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD