Botcraft 1.21.4
Loading...
Searching...
No Matches
ArmorStandEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, ArmorStandEntity::metadata_count> ArmorStandEntity::metadata_names{ {
8 "data_client_flags",
9 "data_head_pose",
10 "data_body_pose",
11 "data_left_arm_pose",
12 "data_right_arm_pose",
13 "data_left_leg_pose",
14 "data_right_leg_pose",
15 } };
16
18 {
19 // Initialize all metadata with default values
21 SetDataHeadPose(Vector3<float>(0.0f, 0.0f, 0.0f));
22 SetDataBodyPose(Vector3<float>(0.0f, 0.0f, 0.0f));
23 SetDataLeftArmPose(Vector3<float>(-10.0f, 0.0f, -10.0f));
24 SetDataRightArmPose(Vector3<float>(-15.0f, 0.0f, 10.0f));
25 SetDataLeftLegPose(Vector3<float>(-1.0f, 0.0f, -1.0f));
26 SetDataRightLegPose(Vector3<float>(1.0f, 0.0f, 1.0f));
27
28 // Initialize all attributes with default values
29#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
31#endif
32 }
33
38
39
40 std::string ArmorStandEntity::GetName() const
41 {
42 return "armor_stand";
43 }
44
49
50
52 {
53 return "armor_stand";
54 }
55
60
61
63 {
65
66 output["metadata"]["data_client_flags"] = GetDataClientFlags();
67 output["metadata"]["data_head_pose"] = GetDataHeadPose().Serialize();
68 output["metadata"]["data_body_pose"] = GetDataBodyPose().Serialize();
69 output["metadata"]["data_left_arm_pose"] = GetDataLeftArmPose().Serialize();
70 output["metadata"]["data_right_arm_pose"] = GetDataRightArmPose().Serialize();
71 output["metadata"]["data_left_leg_pose"] = GetDataLeftLegPose().Serialize();
72 output["metadata"]["data_right_leg_pose"] = GetDataRightLegPose().Serialize();
73
74 return output;
75 }
76
77
78 void ArmorStandEntity::SetMetadataValue(const int index, const std::any& value)
79 {
80 if (index < hierarchy_metadata_count)
81 {
83 }
85 {
86 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
88 }
89 }
90
92 {
93 std::shared_lock<std::shared_mutex> lock(entity_mutex);
94 return std::any_cast<char>(metadata.at("data_client_flags"));
95 }
96
98 {
99 std::shared_lock<std::shared_mutex> lock(entity_mutex);
100 return std::any_cast<Vector3<float>>(metadata.at("data_head_pose"));
101 }
102
104 {
105 std::shared_lock<std::shared_mutex> lock(entity_mutex);
106 return std::any_cast<Vector3<float>>(metadata.at("data_body_pose"));
107 }
108
110 {
111 std::shared_lock<std::shared_mutex> lock(entity_mutex);
112 return std::any_cast<Vector3<float>>(metadata.at("data_left_arm_pose"));
113 }
114
116 {
117 std::shared_lock<std::shared_mutex> lock(entity_mutex);
118 return std::any_cast<Vector3<float>>(metadata.at("data_right_arm_pose"));
119 }
120
122 {
123 std::shared_lock<std::shared_mutex> lock(entity_mutex);
124 return std::any_cast<Vector3<float>>(metadata.at("data_left_leg_pose"));
125 }
126
128 {
129 std::shared_lock<std::shared_mutex> lock(entity_mutex);
130 return std::any_cast<Vector3<float>>(metadata.at("data_right_leg_pose"));
131 }
132
133
134 void ArmorStandEntity::SetDataClientFlags(const char data_client_flags)
135 {
136 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
137 metadata["data_client_flags"] = data_client_flags;
138 }
139
141 {
142 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
143 metadata["data_head_pose"] = data_head_pose;
144 }
145
147 {
148 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
149 metadata["data_body_pose"] = data_body_pose;
150 }
151
153 {
154 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
155 metadata["data_left_arm_pose"] = data_left_arm_pose;
156 }
157
159 {
160 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
161 metadata["data_right_arm_pose"] = data_right_arm_pose;
162 }
163
165 {
166 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
167 metadata["data_left_leg_pose"] = data_left_leg_pose;
168 }
169
171 {
172 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
173 metadata["data_right_leg_pose"] = data_right_leg_pose;
174 }
175
176
178 {
179 return 0.5;
180 }
181
183 {
184 return 1.975;
185 }
186
187}
Vector3< float > GetDataLeftLegPose() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual double GetHeightImpl() const override
static const std::array< std::string, metadata_count > metadata_names
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataRightArmPose(const Vector3< float > &data_right_arm_pose)
virtual std::string GetName() const override
Vector3< float > GetDataLeftArmPose() const
Vector3< float > GetDataBodyPose() const
void SetDataHeadPose(const Vector3< float > &data_head_pose)
static std::string GetClassName()
void SetDataLeftLegPose(const Vector3< float > &data_left_leg_pose)
void SetDataRightLegPose(const Vector3< float > &data_right_leg_pose)
void SetDataBodyPose(const Vector3< float > &data_body_pose)
static EntityType GetClassType()
static constexpr int metadata_count
virtual double GetWidthImpl() const override
void SetDataClientFlags(const char data_client_flags)
Vector3< float > GetDataHeadPose() const
static constexpr int hierarchy_metadata_count
virtual EntityType GetType() const override
Vector3< float > GetDataRightLegPose() const
Vector3< float > GetDataRightArmPose() const
void SetDataLeftArmPose(const Vector3< float > &data_left_arm_pose)
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
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45