Botcraft 1.21.5
Loading...
Searching...
No Matches
WolfEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, WolfEntity::metadata_count> WolfEntity::metadata_names{ {
9#if PROTOCOL_VERSION < 499 /* < 1.15 */
10 "data_health_id",
11#endif
12 "data_interested_id",
13 "data_collar_color",
14#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
15 "data_remaining_anger_time",
16#endif
17#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
18 "data_variant_id",
19#endif
20 } };
21
23 {
24 // Initialize all metadata with default values
25#if PROTOCOL_VERSION < 499 /* < 1.15 */
26 SetDataHealthId(1.0f);
27#endif
30#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
32#endif
33#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
35#endif
36
37 // Initialize all attributes with default values
40#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
42#else
44#endif
45 }
46
48 {
49
50 }
51
52
53 std::string WolfEntity::GetName() const
54 {
55 return "wolf";
56 }
57
59 {
60 return EntityType::Wolf;
61 }
62
63
64 std::string WolfEntity::GetClassName()
65 {
66 return "wolf";
67 }
68
70 {
71 return EntityType::Wolf;
72 }
73
74
76 {
78
79#if PROTOCOL_VERSION < 499 /* < 1.15 */
80 output["metadata"]["data_health_id"] = GetDataHealthId();
81#endif
82 output["metadata"]["data_interested_id"] = GetDataInterestedId();
83 output["metadata"]["data_collar_color"] = GetDataCollarColor();
84#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
85 output["metadata"]["data_remaining_anger_time"] = GetDataRemainingAngerTime();
86#endif
87#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
88 output["metadata"]["data_variant_id"] = GetDataVariantId();
89#endif
90
91 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
92
93 return output;
94 }
95
96
97 void WolfEntity::SetMetadataValue(const int index, const std::any& value)
98 {
99 if (index < hierarchy_metadata_count)
100 {
102 }
103 else if (index - hierarchy_metadata_count < metadata_count)
104 {
105 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
107 }
108 }
109
110#if PROTOCOL_VERSION < 499 /* < 1.15 */
111 float WolfEntity::GetDataHealthId() const
112 {
113 std::shared_lock<std::shared_mutex> lock(entity_mutex);
114 return std::any_cast<float>(metadata.at("data_health_id"));
115 }
116#endif
117
119 {
120 std::shared_lock<std::shared_mutex> lock(entity_mutex);
121 return std::any_cast<bool>(metadata.at("data_interested_id"));
122 }
123
125 {
126 std::shared_lock<std::shared_mutex> lock(entity_mutex);
127 return std::any_cast<int>(metadata.at("data_collar_color"));
128 }
129
130#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
132 {
133 std::shared_lock<std::shared_mutex> lock(entity_mutex);
134 return std::any_cast<int>(metadata.at("data_remaining_anger_time"));
135 }
136#endif
137
138#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
140 {
141 std::shared_lock<std::shared_mutex> lock(entity_mutex);
142 return std::any_cast<int>(metadata.at("data_variant_id"));
143 }
144#endif
145
146
147#if PROTOCOL_VERSION < 499 /* < 1.15 */
148 void WolfEntity::SetDataHealthId(const float data_health_id)
149 {
150 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
151 metadata["data_health_id"] = data_health_id;
152 }
153#endif
154
155 void WolfEntity::SetDataInterestedId(const bool data_interested_id)
156 {
157 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
158 metadata["data_interested_id"] = data_interested_id;
159 }
160
161 void WolfEntity::SetDataCollarColor(const int data_collar_color)
162 {
163 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
164 metadata["data_collar_color"] = data_collar_color;
165 }
166
167#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
168 void WolfEntity::SetDataRemainingAngerTime(const int data_remaining_anger_time)
169 {
170 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
171 metadata["data_remaining_anger_time"] = data_remaining_anger_time;
172 }
173#endif
174
175#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
176 void WolfEntity::SetDataVariantId(const int data_variant_id)
177 {
178 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
179 metadata["data_variant_id"] = data_variant_id;
180 }
181#endif
182
183
185 {
186 std::shared_lock<std::shared_mutex> lock(entity_mutex);
188 }
189
190
191 double WolfEntity::GetWidthImpl() const
192 {
193 return 0.6;
194 }
195
196 double WolfEntity::GetHeightImpl() const
197 {
198 return 0.85;
199 }
200
201}
202#endif
std::shared_mutex entity_mutex
Definition Entity.hpp:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
std::map< EntityAttribute::Type, EntityAttribute > attributes
void SetDataHealthId(const float data_health_id)
float GetDataHealthId() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
static std::string GetClassName()
virtual double GetWidthImpl() const override
int GetDataRemainingAngerTime() const
virtual EntityType GetType() const override
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataVariantId(const int data_variant_id)
static EntityType GetClassType()
virtual std::string GetName() const override
bool GetDataInterestedId() const
int GetDataCollarColor() const
virtual void SetMetadataValue(const int index, const std::any &value) override
static constexpr int hierarchy_metadata_count
void SetDataCollarColor(const int data_collar_color)
int GetDataVariantId() const
virtual double GetHeightImpl() const override
double GetAttributeAttackDamageValue() const
void SetDataInterestedId(const bool data_interested_id)
static const std::array< std::string, metadata_count > metadata_names
static constexpr int metadata_count
void SetDataRemainingAngerTime(const int data_remaining_anger_time)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45