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