Botcraft 1.21.4
Loading...
Searching...
No Matches
TamableAnimalEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, TamableAnimalEntity::metadata_count> TamableAnimalEntity::metadata_names{ {
8 "data_flags_id",
9 "data_owneruuid_id",
10 } };
11
13 {
14 // Initialize all metadata with default values
16 SetDataOwneruuidId(std::optional<ProtocolCraft::UUID>());
17 }
18
23
25 {
26 return true;
27 }
28
29
31 {
33
34 output["metadata"]["data_flags_id"] = GetDataFlagsId();
35 output["metadata"]["data_owneruuid_id"] = GetDataOwneruuidId() ? ProtocolCraft::Json::Value(GetDataOwneruuidId().value()) : ProtocolCraft::Json::Value();
36
37 return output;
38 }
39
40
41 void TamableAnimalEntity::SetMetadataValue(const int index, const std::any& value)
42 {
43 if (index < hierarchy_metadata_count)
44 {
46 }
48 {
49 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
51 }
52 }
53
55 {
56 std::shared_lock<std::shared_mutex> lock(entity_mutex);
57 return std::any_cast<char>(metadata.at("data_flags_id"));
58 }
59
60 std::optional<ProtocolCraft::UUID> TamableAnimalEntity::GetDataOwneruuidId() const
61 {
62 std::shared_lock<std::shared_mutex> lock(entity_mutex);
63 return std::any_cast<std::optional<ProtocolCraft::UUID>>(metadata.at("data_owneruuid_id"));
64 }
65
66
67 void TamableAnimalEntity::SetDataFlagsId(const char data_flags_id)
68 {
69 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
70 metadata["data_flags_id"] = data_flags_id;
71 }
72
73 void TamableAnimalEntity::SetDataOwneruuidId(const std::optional<ProtocolCraft::UUID>& data_owneruuid_id)
74 {
75 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
76 metadata["data_owneruuid_id"] = data_owneruuid_id;
77 }
78
79}
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
virtual bool IsTamableAnimal() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static const std::array< std::string, metadata_count > metadata_names
static constexpr int hierarchy_metadata_count
void SetDataOwneruuidId(const std::optional< ProtocolCraft::UUID > &data_owneruuid_id)
std::optional< ProtocolCraft::UUID > GetDataOwneruuidId() const
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataFlagsId(const char data_flags_id)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45