diff options
author | madmaxoft <github@xoft.cz> | 2014-09-25 23:06:21 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-09-25 23:06:21 +0200 |
commit | 6b260f06ba8ec773e4a81fea38fb123b1ea09081 (patch) | |
tree | 333cb4dc0277f0957d0a23194cd42e4ad7acb3e6 /src/ByteBuffer.cpp | |
parent | Protocol 1.8: Fixed plugin message packet. (diff) | |
download | cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar.gz cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar.bz2 cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar.lz cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar.xz cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.tar.zst cuberite-6b260f06ba8ec773e4a81fea38fb123b1ea09081.zip |
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r-- | src/ByteBuffer.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index e61a90bbc..70fdc008c 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -497,12 +497,15 @@ bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ) return false; } - UInt32 BlockXRaw = (Value >> 38) & 0x3ffffff; - UInt32 BlockYRaw = (Value >> 26) & 0xfff; - UInt32 BlockZRaw = (Value & 0x3ffffff); - a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : -(0x03ffffff - (int)BlockXRaw + 1); - a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : -(0x07ff - (int)BlockYRaw + 1); - a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : -(0x03ffffff - (int)BlockZRaw + 1); + // Convert the 64 received bits into 3 coords: + UInt32 BlockXRaw = (Value >> 38) & 0x03ffffff; // Top 26 bits + UInt32 BlockYRaw = (Value >> 26) & 0x0fff; // Middle 12 bits + UInt32 BlockZRaw = (Value & 0x03ffffff); // Bottom 26 bits + + // If the highest bit in the number's range is set, convert the number into negative: + a_BlockX = ((BlockXRaw & 0x02000000) == 0) ? BlockXRaw : -(0x04000000 - (int)BlockXRaw); + a_BlockY = ((BlockYRaw & 0x0800) == 0) ? BlockYRaw : -(0x0800 - (int)BlockYRaw); + a_BlockZ = ((BlockZRaw & 0x02000000) == 0) ? BlockZRaw : -(0x04000000 - (int)BlockZRaw); return true; } |