Botcraft 1.21.4
Loading...
Searching...
No Matches
ZombieEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, ZombieEntity::metadata_count> ZombieEntity::metadata_names{ {
8 "data_baby_id",
9 "data_special_type_id",
10#if PROTOCOL_VERSION < 405 /* < 1.14 */
11 "data_are_hands_up",
12#endif
13#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
14 "data_drowned_conversion_id",
15#endif
16 } };
17
19 {
20 // Initialize all metadata with default values
21 SetDataBabyId(false);
23#if PROTOCOL_VERSION < 405 /* < 1.14 */
24 SetDataAreHandsUp(false);
25#endif
26#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
28#endif
29
30 // Initialize all attributes with default values
36 }
37
42
43
44 std::string ZombieEntity::GetName() const
45 {
46 return "zombie";
47 }
48
53
54
56 {
57 return "zombie";
58 }
59
64
65
67 {
69
70 output["metadata"]["data_baby_id"] = GetDataBabyId();
71 output["metadata"]["data_special_type_id"] = GetDataSpecialTypeId();
72#if PROTOCOL_VERSION < 405 /* < 1.14 */
73 output["metadata"]["data_are_hands_up"] = GetDataAreHandsUp();
74#endif
75#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
76 output["metadata"]["data_drowned_conversion_id"] = GetDataDrownedConversionId();
77#endif
78
79 output["attributes"]["spawn_reinforcements"] = GetAttributeSpawnReinforcementsChanceValue();
80
81 return output;
82 }
83
84
85 void ZombieEntity::SetMetadataValue(const int index, const std::any& value)
86 {
87 if (index < hierarchy_metadata_count)
88 {
90 }
92 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 }
96 }
97
99 {
100 std::shared_lock<std::shared_mutex> lock(entity_mutex);
101 return std::any_cast<bool>(metadata.at("data_baby_id"));
102 }
103
105 {
106 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 return std::any_cast<int>(metadata.at("data_special_type_id"));
108 }
109
110#if PROTOCOL_VERSION < 405 /* < 1.14 */
111 bool ZombieEntity::GetDataAreHandsUp() const
112 {
113 std::shared_lock<std::shared_mutex> lock(entity_mutex);
114 return std::any_cast<bool>(metadata.at("data_are_hands_up"));
115 }
116#endif
117
118#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
120 {
121 std::shared_lock<std::shared_mutex> lock(entity_mutex);
122 return std::any_cast<bool>(metadata.at("data_drowned_conversion_id"));
123 }
124#endif
125
126
127 void ZombieEntity::SetDataBabyId(const bool data_baby_id)
128 {
129 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
130 metadata["data_baby_id"] = data_baby_id;
131 }
132
133 void ZombieEntity::SetDataSpecialTypeId(const int data_special_type_id)
134 {
135 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
136 metadata["data_special_type_id"] = data_special_type_id;
137 }
138
139#if PROTOCOL_VERSION < 405 /* < 1.14 */
140 void ZombieEntity::SetDataAreHandsUp(const bool data_are_hands_up)
141 {
142 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
143 metadata["data_are_hands_up"] = data_are_hands_up;
144 }
145#endif
146
147#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
148 void ZombieEntity::SetDataDrownedConversionId(const bool data_drowned_conversion_id)
149 {
150 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
151 metadata["data_drowned_conversion_id"] = data_drowned_conversion_id;
152 }
153#endif
154
155
157 {
158 std::shared_lock<std::shared_mutex> lock(entity_mutex);
160 }
161
162
164 {
165 return 0.6;
166 }
167
169 {
170 return 1.95;
171 }
172
173}
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
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 ProtocolCraft::Json::Value Serialize() const override
static constexpr int hierarchy_metadata_count
bool GetDataDrownedConversionId() const
static EntityType GetClassType()
virtual void SetMetadataValue(const int index, const std::any &value) override
static std::string GetClassName()
virtual ProtocolCraft::Json::Value Serialize() const override
virtual double GetWidthImpl() const override
int GetDataSpecialTypeId() const
virtual EntityType GetType() const override
virtual std::string GetName() const override
virtual double GetHeightImpl() const override
static const std::array< std::string, metadata_count > metadata_names
void SetDataDrownedConversionId(const bool data_drowned_conversion_id)
double GetAttributeSpawnReinforcementsChanceValue() const
static constexpr int metadata_count
void SetDataSpecialTypeId(const int data_special_type_id)
void SetDataBabyId(const bool data_baby_id)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45