From f8e86ab9baa971d6dfd25e22e7a6fecc83602893 Mon Sep 17 00:00:00 2001 From: Alpyne Date: Sat, 31 Oct 2020 01:18:28 -0700 Subject: [PATCH] Implement PacketReader method ReadPosition --- src/PacketReader.h | 5 +++++ src/Types.h | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/PacketReader.h b/src/PacketReader.h index 93b6b24..1302828 100644 --- a/src/PacketReader.h +++ b/src/PacketReader.h @@ -105,6 +105,11 @@ namespace Feather return str; } + inline BlockPos ReadPosition() + { + return BlockPos(Read()); + } + uint32_t Length() const { return m_length; } uint32_t Size() const { return m_length + m_lengthSize; } diff --git a/src/Types.h b/src/Types.h index b6bf99d..def64f6 100644 --- a/src/Types.h +++ b/src/Types.h @@ -23,10 +23,19 @@ namespace Feather struct BlockPos { - const int32_t x, y, z; + int32_t x, y, z; BlockPos(int32_t x, int32_t y, int32_t z) : x(x), y(y), z(z) {} + // Decodes from packed long + BlockPos(int64_t l) + : x(l << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH)) + , y(l << (64 - Y_OFFSET - PACKED_Y_LENGTH) >> (64 - PACKED_Y_LENGTH)) + , z(l << (64 - Z_OFFSET - PACKED_Z_LENGTH) >> (64 - PACKED_Z_LENGTH)) + {} + + BlockPos() : BlockPos(0, 0, 0) {} + inline int64_t Encode() { int64_t l = 0;