summaryrefslogtreecommitdiffstats
path: root/src/ByteBuffer.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2014-09-22 21:45:22 +0200
committerAlexander Harkness <me@bearbin.net>2014-09-22 21:45:22 +0200
commit5f823fd18dbfc097b45957d05aeb4d04bf5099fd (patch)
tree8fa683aca43dfabd59c7c90e06c2d1f1a4549bed /src/ByteBuffer.cpp
parentMerge pull request #1446 from cedeel/patch-1 (diff)
parentChanged metadata reading again. (diff)
downloadcuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar.gz
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar.bz2
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar.lz
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar.xz
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.tar.zst
cuberite-5f823fd18dbfc097b45957d05aeb4d04bf5099fd.zip
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r--src/ByteBuffer.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96556bf61..17e8091c7 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -267,7 +267,7 @@ size_t cByteBuffer::GetReadableSpace(void) const
}
// Single readable space partition:
ASSERT(m_WritePos >= m_ReadPos);
- return m_WritePos - m_ReadPos ;
+ return m_WritePos - m_ReadPos;
}
@@ -489,6 +489,27 @@ bool cByteBuffer::ReadLEInt(int & a_Value)
+bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+{
+ Int64 Value;
+ if (!ReadBEInt64(Value))
+ {
+ return false;
+ }
+
+ UInt32 BlockXRaw = (Value >> 38) & 0x3ffffff;
+ UInt32 BlockYRaw = (Value >> 26) & 0xfff;
+ UInt32 BlockZRaw = (Value & 0x3ffffff);
+ a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : (~(BlockXRaw & 0x1ffffff)) + 1;
+ a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : (~(BlockXRaw & 0x7ff)) + 1;
+ a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : (~(BlockZRaw & 0x1ffffff)) + 1;
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::WriteChar(char a_Value)
{
CHECK_THREAD;
@@ -661,6 +682,15 @@ bool cByteBuffer::WriteLEInt(int a_Value)
+bool cByteBuffer::WritePosition(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
+}
+
+
+
+
+
bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;