Botcraft 1.21.4
Loading...
Searching...
No Matches
PandaEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, PandaEntity::metadata_count> PandaEntity::metadata_names{ {
9 "unhappy_counter",
10 "sneeze_counter",
11 "eat_counter",
12 "main_gene_id",
13 "hidden_gene_id",
14 "data_id_flags",
15 } };
16
18 {
19 // Initialize all metadata with default values
26
27 // Initialize all attributes with default values
30 }
31
36
37
38 std::string PandaEntity::GetName() const
39 {
40 return "panda";
41 }
42
47
48
50 {
51 return "panda";
52 }
53
58
59
61 {
63
64 output["metadata"]["unhappy_counter"] = GetUnhappyCounter();
65 output["metadata"]["sneeze_counter"] = GetSneezeCounter();
66 output["metadata"]["eat_counter"] = GetEatCounter();
67 output["metadata"]["main_gene_id"] = GetMainGeneId();
68 output["metadata"]["hidden_gene_id"] = GetHiddenGeneId();
69 output["metadata"]["data_id_flags"] = GetDataIdFlags();
70
71 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
72
73 return output;
74 }
75
76
77 void PandaEntity::SetMetadataValue(const int index, const std::any& value)
78 {
79 if (index < hierarchy_metadata_count)
80 {
82 }
84 {
85 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
87 }
88 }
89
91 {
92 std::shared_lock<std::shared_mutex> lock(entity_mutex);
93 return std::any_cast<int>(metadata.at("unhappy_counter"));
94 }
95
97 {
98 std::shared_lock<std::shared_mutex> lock(entity_mutex);
99 return std::any_cast<int>(metadata.at("sneeze_counter"));
100 }
101
103 {
104 std::shared_lock<std::shared_mutex> lock(entity_mutex);
105 return std::any_cast<int>(metadata.at("eat_counter"));
106 }
107
109 {
110 std::shared_lock<std::shared_mutex> lock(entity_mutex);
111 return std::any_cast<char>(metadata.at("main_gene_id"));
112 }
113
115 {
116 std::shared_lock<std::shared_mutex> lock(entity_mutex);
117 return std::any_cast<char>(metadata.at("hidden_gene_id"));
118 }
119
121 {
122 std::shared_lock<std::shared_mutex> lock(entity_mutex);
123 return std::any_cast<char>(metadata.at("data_id_flags"));
124 }
125
126
127 void PandaEntity::SetUnhappyCounter(const int unhappy_counter)
128 {
129 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
130 metadata["unhappy_counter"] = unhappy_counter;
131 }
132
133 void PandaEntity::SetSneezeCounter(const int sneeze_counter)
134 {
135 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
136 metadata["sneeze_counter"] = sneeze_counter;
137 }
138
139 void PandaEntity::SetEatCounter(const int eat_counter)
140 {
141 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
142 metadata["eat_counter"] = eat_counter;
143 }
144
145 void PandaEntity::SetMainGeneId(const char main_gene_id)
146 {
147 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
148 metadata["main_gene_id"] = main_gene_id;
149 }
150
151 void PandaEntity::SetHiddenGeneId(const char hidden_gene_id)
152 {
153 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
154 metadata["hidden_gene_id"] = hidden_gene_id;
155 }
156
157 void PandaEntity::SetDataIdFlags(const char data_id_flags)
158 {
159 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
160 metadata["data_id_flags"] = data_id_flags;
161 }
162
163
165 {
166 std::shared_lock<std::shared_mutex> lock(entity_mutex);
168 }
169
170
172 {
173 return 1.3;
174 }
175
177 {
178 return 1.25;
179 }
180
181}
182#endif
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
std::map< EntityAttribute::Type, EntityAttribute > attributes
static constexpr int metadata_count
virtual std::string GetName() const override
void SetUnhappyCounter(const int unhappy_counter)
void SetMainGeneId(const char main_gene_id)
virtual double GetHeightImpl() const override
static std::string GetClassName()
static EntityType GetClassType()
virtual void SetMetadataValue(const int index, const std::any &value) override
int GetUnhappyCounter() const
char GetMainGeneId() const
void SetHiddenGeneId(const char hidden_gene_id)
virtual double GetWidthImpl() const override
double GetAttributeAttackDamageValue() const
char GetHiddenGeneId() const
void SetDataIdFlags(const char data_id_flags)
virtual ProtocolCraft::Json::Value Serialize() const override
static const std::array< std::string, metadata_count > metadata_names
int GetSneezeCounter() const
void SetEatCounter(const int eat_counter)
void SetSneezeCounter(const int sneeze_counter)
virtual EntityType GetType() const override
char GetDataIdFlags() const
static constexpr int hierarchy_metadata_count
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45