Botcraft 1.21.8
Loading...
Searching...
No Matches
Display.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
3
5
9
10namespace ProtocolCraft
11{
12 namespace Components
13 {
17
19 {
20 if (type <= ItemAttributeModifiersDisplayType::None || type >= ItemAttributeModifiersDisplayType::NUM_DISPLAY_TYPES)
21 {
22 throw std::runtime_error("Unable to create ItemAttributeModifiersDisplayData with id: " + std::to_string(static_cast<int>(type)) + ".");
23 }
24 Type = type;
25
26 switch (Type)
27 {
29 Data = std::make_shared<DefaultDisplay>();
30 break;
32 Data = std::make_shared<HiddenDisplay>();
33 break;
35 Data = std::make_shared<OverrideDisplay>();
36 break;
37 default:
38 // This should not happen
39 throw std::runtime_error("Unable to create ItemAttributeModifiersDisplayData with id: " + std::to_string(static_cast<int>(Type)) + ".");
40 Data = nullptr;
41 break;
42 }
43 return *this;
44 }
45
46
48 {
49 SetType(ReadData<ItemAttributeModifiersDisplayType, VarInt>(iter, length));
50 if (GetData() != nullptr)
51 {
52 GetData()->Read(iter, length);
53 }
54 }
55
57 {
58 WriteData<ItemAttributeModifiersDisplayType, VarInt>(GetType(), container);
59 if (GetData() != nullptr)
60 {
61 GetData()->Write(container);
62 }
63 }
64
66 {
67 Json::Value output;
68
69 output[std::string(field_name<Type_index>)] = Type;
70 output[std::string(field_name<Data_index>)] = Data == nullptr ? Json::Object() : Data->Serialize();
71
72 return output;
73 }
74 }
75}
76#endif
#define DEFINE_NETWORK_TYPE(ClassName)
ItemAttributeModifiersDisplay & SetType(const ItemAttributeModifiersDisplayType type_)
Definition Display.cpp:18
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
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator