Botcraft 1.21.8
Loading...
Searching...
No Matches
TrackedWaypoint.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
3
5
10
12
13namespace ProtocolCraft
14{
19
21
23 {
24 if (type <= TrackedWaypointType::None || type >= TrackedWaypointType::NUM_WAYPOINT_TYPES)
25 {
26 throw std::runtime_error("Unable to create particle with id: " + std::to_string(static_cast<int>(type)) + ".");
27 }
28 Type = type;
29 switch (Type)
30 {
32 Data = std::make_shared<EmptyWaypoint>();
33 break;
35 Data = std::make_shared<Vec3iWaypoint>();
36 break;
38 Data = std::make_shared<ChunkWaypoint>();
39 break;
41 Data = std::make_shared<AzimuthWaypoint>();
42 break;
43 default: // Should not happen
44 throw std::runtime_error("Unable to create TrackedWaypointData with id: " + std::to_string(static_cast<int>(Type)) + ".");
45 break;
46 }
47 return *this;
48 }
49
50 void TrackedWaypoint::ReadImpl(ReadIterator& iter, size_t& length)
51 {
52 Identifier = ReadData<Either<UUID, std::string>>(iter, length);
53 Icon = ReadData<WaypointIcon>(iter, length);
54 SetType(ReadData<TrackedWaypointType, VarInt>(iter, length));
55 if (Data != nullptr)
56 {
57 Data->Read(iter, length);
58 }
59 }
60
61 void TrackedWaypoint::WriteImpl(WriteContainer& container) const
62 {
63 WriteData<Either<UUID, std::string>>(Identifier, container);
64 WriteData<WaypointIcon>(Icon, container);
65 WriteData<TrackedWaypointType, VarInt>(Type, container);
66 if (Data != nullptr)
67 {
68 Data->Write(container);
69 }
70 }
71
72 Json::Value TrackedWaypoint::SerializeImpl() const
73 {
74 Json::Value output;
75
76 output[std::string(field_name<Identifier_index>)] = Identifier;
77 output[std::string(field_name<Icon_index>)] = Icon;
78 output[std::string(field_name<Type_index>)] = Type;
79 output[std::string(field_name<Data_index>)] = Data == nullptr ? Json::Object() : Data->Serialize();
80
81 return output;
82 }
83}
84#endif
#define DEFINE_NETWORK_TYPE(ClassName)
virtual Json::Value SerializeImpl() const =0
virtual void WriteImpl(WriteContainer &container) const =0
virtual Json::Value Serialize() const
virtual void ReadImpl(ReadIterator &iter, size_t &length)=0
TrackedWaypoint & SetType(const TrackedWaypointType type)
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator