Botcraft 26.1.2
Loading...
Searching...
No Matches
AgeableMobEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, AgeableMobEntity::metadata_count> AgeableMobEntity::metadata_names{ {
8 "data_baby_id",
9#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
10 "age_locked",
11#endif
12 } };
13
15 {
16 // Initialize all metadata with default values
17 SetDataBabyId(false);
18#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
19 SetAgeLocked(false);
20#endif
21 }
22
27
29 {
30 return true;
31 }
32
33
35 {
37
38 output["metadata"]["data_baby_id"] = GetDataBabyId();
39#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
40 output["metadata"]["age_locked"] = GetAgeLocked();
41#endif
42
43 return output;
44 }
45
46
47 void AgeableMobEntity::SetMetadataValue(const int index, const std::any& value)
48 {
49 if (index < hierarchy_metadata_count)
50 {
52 }
54 {
55 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
57 }
58 }
59
61 {
62 std::shared_lock<std::shared_mutex> lock(entity_mutex);
63 return std::any_cast<bool>(metadata.at("data_baby_id"));
64 }
65
66#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
68 {
69 std::shared_lock<std::shared_mutex> lock(entity_mutex);
70 return std::any_cast<bool>(metadata.at("age_locked"));
71 }
72#endif
73
74
75 void AgeableMobEntity::SetDataBabyId(const bool data_baby_id)
76 {
77 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
78 metadata["data_baby_id"] = data_baby_id;
79 }
80
81#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
82 void AgeableMobEntity::SetAgeLocked(const bool age_locked)
83 {
84 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
85 metadata["age_locked"] = age_locked;
86 }
87#endif
88
89}
void SetAgeLocked(const bool age_locked)
static constexpr int metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
static const std::array< std::string, metadata_count > metadata_names
static constexpr int hierarchy_metadata_count
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual bool IsAgeableMob() const override
void SetDataBabyId(const bool data_baby_id)
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1242
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:769
std::shared_mutex entity_mutex
Definition Entity.hpp:267
std::map< std::string, std::any > metadata
Definition Entity.hpp:282
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45