Botcraft 26.3
Loading...
Searching...
No Matches
ClientboundMoveEntityPacketPos.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#if PROTOCOL_VERSION > 776 /* > 26.2 */
6#include <array>
7#include <optional>
8#include <utility>
9#include <vector>
10#endif
11
12namespace ProtocolCraft
13{
14 class ClientboundMoveEntityPacketPos : public BasePacket<ClientboundMoveEntityPacketPos>
15 {
16 public:
17 static constexpr std::string_view packet_name = "Move Entity Pos";
18
19#if PROTOCOL_VERSION > 776 /* > 26.2 */
20 DEFINE_CONDITION(IsSingleStep, GetStepCount() <= 0);
21
22 private:
23 std::optional<std::vector<std::pair<int, std::array<short, 3>>>> ReadStepped(ReadIterator& iter, size_t& length) const
24 {
25 const int step_count = GetStepCount();
26 if (step_count > 0)
27 {
28 std::vector<std::pair<int, std::array<short, 3>>> deltas(step_count);
29 for (int i = 0; i < step_count; ++i)
30 {
31 deltas[i].first = ReadData<VarInt>(iter, length);
32 deltas[i].second = ReadData<std::array<short, 3>>(iter, length);
33 }
34 return deltas;
35 }
36 return std::nullopt;
37 }
38
39 void WriteStepped(const std::optional<std::vector<std::pair<int, std::array<short, 3>>>>& stepped_deltas_, WriteContainer& c) const
40 {
41 if (stepped_deltas_.has_value())
42 {
43 const std::vector<std::pair<int, std::array<short, 3>>>& v = stepped_deltas_.value();
44 for (size_t i = 0; i < v.size(); ++i)
45 {
46 WriteData<VarInt>(v[i].first, c);
47 WriteData<std::array<short, 3>>(v[i].second, c);
48 }
49 }
50 }
51#endif
52
54#if PROTOCOL_VERSION < 107 /* < 1.9 */
55 SERIALIZED_FIELD(XA, char);
56 SERIALIZED_FIELD(YA, char);
57 SERIALIZED_FIELD(ZA, char);
58 SERIALIZED_FIELD(OnGround, bool);
59#elif PROTOCOL_VERSION < 777 /* < 26.3 */
60 SERIALIZED_FIELD(XA, short);
61 SERIALIZED_FIELD(YA, short);
62 SERIALIZED_FIELD(ZA, short);
63 SERIALIZED_FIELD(OnGround, bool);
64#else
66 SERIALIZED_FIELD(SingleDelta, Internal::Conditioned<std::array<short, 3>, &THIS::IsSingleStep>);
67 SERIALIZED_FIELD(SteppedDeltas, Internal::CustomType<std::optional<std::vector<std::pair<int, std::array<short, 3>>>>, &THIS::ReadStepped, &THIS::WriteStepped, nullptr>);
68#endif
69
70#if PROTOCOL_VERSION > 776 /* > 26.2 */
71 public:
72 bool GetOnGround() const
73 {
74 return static_cast<bool>(Properties & 1);
75 }
76
77 THIS& SetOnGround(const bool b)
78 {
79 Properties = (Properties & ~1) | static_cast<int>(b);
80 return *this;
81 }
82
83 int GetStepCount() const
84 {
85 return Properties >> 1;
86 }
87
88 THIS& SetStepCount(const int i)
89 {
90 Properties = (Properties & 1) | (i << 1);
91 return *this;
92 }
93#endif
94
96 };
97} //ProtocolCraft
#define SERIALIZED_FIELD(Name,...)
DEFINE_CONDITION(IsSingleStep, GetStepCount()<=0)
void WriteStepped(const std::optional< std::vector< std::pair< int, std::array< short, 3 > > > > &stepped_deltas_, WriteContainer &c) const
SERIALIZED_FIELD_WITHOUT_GETTER_SETTER(Properties, VarInt)
SERIALIZED_FIELD(SingleDelta, Internal::Conditioned< std::array< short, 3 >, &THIS::IsSingleStep >)
std::optional< std::vector< std::pair< int, std::array< short, 3 > > > > ReadStepped(ReadIterator &iter, size_t &length) const
SERIALIZED_FIELD(SteppedDeltas, Internal::CustomType< std::optional< std::vector< std::pair< int, std::array< short, 3 > > > >, &THIS::ReadStepped, &THIS::WriteStepped, nullptr >)
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator
A type wrapper to conditionally serialize a type.
Definition Templates.hpp:83