Botcraft 1.21.4
Loading...
Searching...
No Matches
WolfEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, WolfEntity::metadata_count> WolfEntity::metadata_names{ {
8#if PROTOCOL_VERSION < 499 /* < 1.15 */
9 "data_health_id",
10#endif
11 "data_interested_id",
12 "data_collar_color",
13#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
14 "data_remaining_anger_time",
15#endif
16#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
17 "data_variant_id",
18#endif
19 } };
20
22 {
23 // Initialize all metadata with default values
24#if PROTOCOL_VERSION < 499 /* < 1.15 */
25 SetDataHealthId(1.0f);
26#endif
29#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
31#endif
32#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
34#endif
35
36 // Initialize all attributes with default values
39#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
41#else
43#endif
44 }
45
50
51
52 std::string WolfEntity::GetName() const
53 {
54 return "wolf";
55 }
56
58 {
59 return EntityType::Wolf;
60 }
61
62
64 {
65 return "wolf";
66 }
67
72
73
75 {
77
78#if PROTOCOL_VERSION < 499 /* < 1.15 */
79 output["metadata"]["data_health_id"] = GetDataHealthId();
80#endif
81 output["metadata"]["data_interested_id"] = GetDataInterestedId();
82 output["metadata"]["data_collar_color"] = GetDataCollarColor();
83#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
84 output["metadata"]["data_remaining_anger_time"] = GetDataRemainingAngerTime();
85#endif
86#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
87 output["metadata"]["data_variant_id"] = GetDataVariantId();
88#endif
89
90 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
91
92 return output;
93 }
94
95
96 void WolfEntity::SetMetadataValue(const int index, const std::any& value)
97 {
98 if (index < hierarchy_metadata_count)
99 {
101 }
102 else if (index - hierarchy_metadata_count < metadata_count)
103 {
104 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
106 }
107 }
108
109#if PROTOCOL_VERSION < 499 /* < 1.15 */
110 float WolfEntity::GetDataHealthId() const
111 {
112 std::shared_lock<std::shared_mutex> lock(entity_mutex);
113 return std::any_cast<float>(metadata.at("data_health_id"));
114 }
115#endif
116
118 {
119 std::shared_lock<std::shared_mutex> lock(entity_mutex);
120 return std::any_cast<bool>(metadata.at("data_interested_id"));
121 }
122
124 {
125 std::shared_lock<std::shared_mutex> lock(entity_mutex);
126 return std::any_cast<int>(metadata.at("data_collar_color"));
127 }
128
129#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
131 {
132 std::shared_lock<std::shared_mutex> lock(entity_mutex);
133 return std::any_cast<int>(metadata.at("data_remaining_anger_time"));
134 }
135#endif
136
137#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
139 {
140 std::shared_lock<std::shared_mutex> lock(entity_mutex);
141 return std::any_cast<int>(metadata.at("data_variant_id"));
142 }
143#endif
144
145
146#if PROTOCOL_VERSION < 499 /* < 1.15 */
147 void WolfEntity::SetDataHealthId(const float data_health_id)
148 {
149 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
150 metadata["data_health_id"] = data_health_id;
151 }
152#endif
153
154 void WolfEntity::SetDataInterestedId(const bool data_interested_id)
155 {
156 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
157 metadata["data_interested_id"] = data_interested_id;
158 }
159
160 void WolfEntity::SetDataCollarColor(const int data_collar_color)
161 {
162 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
163 metadata["data_collar_color"] = data_collar_color;
164 }
165
166#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
167 void WolfEntity::SetDataRemainingAngerTime(const int data_remaining_anger_time)
168 {
169 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
170 metadata["data_remaining_anger_time"] = data_remaining_anger_time;
171 }
172#endif
173
174#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
175 void WolfEntity::SetDataVariantId(const int data_variant_id)
176 {
177 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
178 metadata["data_variant_id"] = data_variant_id;
179 }
180#endif
181
182
184 {
185 std::shared_lock<std::shared_mutex> lock(entity_mutex);
187 }
188
189
191 {
192 return 0.6;
193 }
194
196 {
197 return 0.85;
198 }
199
200}
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 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