Botcraft 1.21.4
Loading...
Searching...
No Matches
ClientboundSetEquipmentPacket.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace ProtocolCraft
8{
9 class ClientboundSetEquipmentPacket : public BaseMessage<ClientboundSetEquipmentPacket>
10 {
11 public:
12 static constexpr std::string_view packet_name = "Set Equipment";
13
14#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
15 private:
16 std::map<unsigned char, Slot> ReadSlots(ReadIterator& iter, size_t& length) const
17 {
18 bool has_value = true;
19 std::map<unsigned char, Slot> slots;
20 while (has_value)
21 {
22 unsigned char current_value = ReadData<unsigned char>(iter, length);
23
24 slots.insert({ static_cast<unsigned char>(current_value & 0x7F), ReadData<Slot>(iter, length) });
25
26 has_value = current_value & (1 << 7);
27 }
28 return slots;
29 }
30
31 void WriteSlots(const std::map<unsigned char, Slot>& slots, WriteContainer& container) const
32 {
33 size_t index = 0;
34 for (const auto& [k, v] : slots)
35 {
36 WriteData<unsigned char>(index != slots.size() - 1 ? k | (1 << 7) : k, container);
37 WriteData<Slot>(v, container);
38 }
39 }
40#endif
41
43#if PROTOCOL_VERSION < 735 /* < 1.16 */
44 SERIALIZED_FIELD(Slot, std::pair<VarInt, ProtocolCraft::Slot>);
45#else
46 SERIALIZED_FIELD(Slots, Internal::CustomType<std::map<unsigned char, Slot>, &THIS::ReadSlots, &THIS::WriteSlots>);
47#endif
48
50 };
51} //ProtocolCraft
#define SERIALIZED_FIELD(Name,...)
void WriteSlots(const std::map< unsigned char, Slot > &slots, WriteContainer &container) const
SERIALIZED_FIELD(Slots, Internal::CustomType< std::map< unsigned char, Slot >, &THIS::ReadSlots, &THIS::WriteSlots >)
std::map< unsigned char, Slot > ReadSlots(ReadIterator &iter, size_t &length) const
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator