Botcraft 1.21.4
Loading...
Searching...
No Matches
VillagerEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, VillagerEntity::metadata_count> VillagerEntity::metadata_names{ {
8#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
9 "data_villager_data",
10#else
11 "data_villager_profession_id",
12#endif
13 } };
14
16 {
17 // Initialize all metadata with default values
18#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
20#else
21 SetDataVillagerProfessionId(0);
22#endif
23
24 // Initialize all attributes with default values
26#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
28#endif
29 }
30
35
36
37 std::string VillagerEntity::GetName() const
38 {
39 return "villager";
40 }
41
46
47
49 {
50 return "villager";
51 }
52
57
58
60 {
61#if PROTOCOL_VERSION > 477 /* > 1.14 */
63#else
65#endif
66
67#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
68 output["metadata"]["data_villager_data"] = { GetDataVillagerData().type, GetDataVillagerData().profession, GetDataVillagerData().level };
69#else
70 output["metadata"]["data_villager_profession_id"] = std::any_cast<int>(GetDataVillagerProfessionId());
71#endif
72
73 return output;
74 }
75
76
77 void VillagerEntity::SetMetadataValue(const int index, const std::any& value)
78 {
79 if (index < hierarchy_metadata_count)
80 {
81#if PROTOCOL_VERSION > 477 /* > 1.14 */
83#else
85#endif
86 }
88 {
89 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
91 }
92 }
93
94#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
96 {
97 std::shared_lock<std::shared_mutex> lock(entity_mutex);
98 return std::any_cast<VillagerData>(metadata.at("data_villager_data"));
99 }
100
101
102 void VillagerEntity::SetDataVillagerData(const VillagerData& data_villager_data)
103 {
104 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
105 metadata["data_villager_data"] = data_villager_data;
106 }
107#else
108 int VillagerEntity::GetDataVillagerProfessionId() const
109 {
110 std::shared_lock<std::shared_mutex> lock(entity_mutex);
111 return std::any_cast<int>(metadata.at("data_villager_profession_id"));
112 }
113
114
115 void VillagerEntity::SetDataVillagerProfessionId(const int data_villager_profession_id)
116 {
117 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
118 metadata["data_villager_profession_id"] = data_villager_profession_id;
119 }
120#endif
121
122
124 {
125 return 0.6;
126 }
127
129 {
130 return 1.95;
131 }
132
133}
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
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 void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
VillagerData GetDataVillagerData() const
static const std::array< std::string, metadata_count > metadata_names
virtual double GetHeightImpl() const override
virtual EntityType GetType() const override
static constexpr int metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataVillagerData(const VillagerData &data_villager_data)
static constexpr int hierarchy_metadata_count
static std::string GetClassName()
virtual double GetWidthImpl() const override
static EntityType GetClassType()
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45