Botcraft 1.21.4
Loading...
Searching...
No Matches
ShulkerEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, ShulkerEntity::metadata_count> ShulkerEntity::metadata_names{ {
8 "data_attach_face_id",
9#if PROTOCOL_VERSION < 755 /* < 1.17 */
10 "data_attach_pos_id",
11#endif
12 "data_peek_id",
13 "data_color_id",
14 } };
15
17 {
18 // Initialize all metadata with default values
20#if PROTOCOL_VERSION < 755 /* < 1.17 */
21 SetDataAttachPosId(std::optional<Position>());
22#endif
25
26 // Initialize all attributes with default values
28 }
29
34
35
36 std::string ShulkerEntity::GetName() const
37 {
38 return "shulker";
39 }
40
45
46
48 {
49 return "shulker";
50 }
51
56
57
59 {
61
62 output["metadata"]["data_attach_face_id"] = static_cast<int>(GetDataAttachFaceId());
63#if PROTOCOL_VERSION < 755 /* < 1.17 */
64 output["metadata"]["data_attach_pos_id"] = GetDataAttachPosId() ? GetDataAttachPosId().value().Serialize() : ProtocolCraft::Json::Value();
65#endif
66 output["metadata"]["data_peek_id"] = GetDataPeekId();
67 output["metadata"]["data_color_id"] = GetDataColorId();
68
69 return output;
70 }
71
72
73 void ShulkerEntity::SetMetadataValue(const int index, const std::any& value)
74 {
75 if (index < hierarchy_metadata_count)
76 {
78 }
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
83 }
84 }
85
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<Direction>(metadata.at("data_attach_face_id"));
90 }
91
92#if PROTOCOL_VERSION < 755 /* < 1.17 */
93 std::optional<Position> ShulkerEntity::GetDataAttachPosId() const
94 {
95 std::shared_lock<std::shared_mutex> lock(entity_mutex);
96 return std::any_cast<std::optional<Position>>(metadata.at("data_attach_pos_id"));
97 }
98#endif
99
101 {
102 std::shared_lock<std::shared_mutex> lock(entity_mutex);
103 return std::any_cast<char>(metadata.at("data_peek_id"));
104 }
105
107 {
108 std::shared_lock<std::shared_mutex> lock(entity_mutex);
109 return std::any_cast<char>(metadata.at("data_color_id"));
110 }
111
112
113 void ShulkerEntity::SetDataAttachFaceId(const Direction data_attach_face_id)
114 {
115 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
116 metadata["data_attach_face_id"] = data_attach_face_id;
117 }
118
119#if PROTOCOL_VERSION < 755 /* < 1.17 */
120 void ShulkerEntity::SetDataAttachPosId(const std::optional<Position>& data_attach_pos_id)
121 {
122 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
123 metadata["data_attach_pos_id"] = data_attach_pos_id;
124 }
125#endif
126
127 void ShulkerEntity::SetDataPeekId(const char data_peek_id)
128 {
129 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
130 metadata["data_peek_id"] = data_peek_id;
131 }
132
133 void ShulkerEntity::SetDataColorId(const char data_color_id)
134 {
135 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
136 metadata["data_color_id"] = data_color_id;
137 }
138
139
141 {
142 return 1.0;
143 }
144
146 {
147 return 1.0;
148 }
149
150}
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1095
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
std::map< EntityAttribute::Type, EntityAttribute > attributes
void SetDataPeekId(const char data_peek_id)
static const std::array< std::string, metadata_count > metadata_names
virtual std::string GetName() const override
static EntityType GetClassType()
Direction GetDataAttachFaceId() const
virtual double GetHeightImpl() const override
virtual EntityType GetType() const override
static constexpr int metadata_count
static std::string GetClassName()
static constexpr int hierarchy_metadata_count
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual double GetWidthImpl() const override
void SetDataAttachFaceId(const Direction data_attach_face_id)
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataColorId(const char data_color_id)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45