Botcraft 1.21.8
Loading...
Searching...
No Matches
GhastEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, GhastEntity::metadata_count> GhastEntity::metadata_names{ {
8 "data_is_charging",
9 } };
10
12 {
13 // Initialize all metadata with default values
14 SetDataIsCharging(false);
15
16 // Initialize all attributes with default values
19#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
22#endif
23 }
24
29
30
31 std::string GhastEntity::GetName() const
32 {
33 return "ghast";
34 }
35
40
41
43 {
44 return "ghast";
45 }
46
51
52
54 {
55#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
56 ProtocolCraft::Json::Value output = FlyingMobEntity::Serialize();
57#else
59#endif
60
61 output["metadata"]["data_is_charging"] = GetDataIsCharging();
62
63#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
64 output["attributes"]["flying_speed"] = GetAttributeFlyingSpeedValue();
65#endif
66
67 return output;
68 }
69
70
71 void GhastEntity::SetMetadataValue(const int index, const std::any& value)
72 {
73 if (index < hierarchy_metadata_count)
74 {
75#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
76 FlyingMobEntity::SetMetadataValue(index, value);
77#else
78 MobEntity::SetMetadataValue(index, value);
79#endif
80 }
82 {
83 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
85 }
86 }
87
89 {
90 std::shared_lock<std::shared_mutex> lock(entity_mutex);
91 return std::any_cast<bool>(metadata.at("data_is_charging"));
92 }
93
94
95 void GhastEntity::SetDataIsCharging(const bool data_is_charging)
96 {
97 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
98 metadata["data_is_charging"] = data_is_charging;
99 }
100
101
102#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
104 {
105 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 }
108#endif
109
110
112 {
113 return 4.0;
114 }
115
117 {
118 return 4.0;
119 }
120
121}
std::shared_mutex entity_mutex
Definition Entity.hpp:261
std::map< std::string, std::any > metadata
Definition Entity.hpp:276
static constexpr int metadata_count
bool GetDataIsCharging() const
virtual double GetHeightImpl() const override
static const std::array< std::string, metadata_count > metadata_names
virtual void SetMetadataValue(const int index, const std::any &value) override
static EntityType GetClassType()
virtual double GetWidthImpl() const override
static constexpr int hierarchy_metadata_count
static std::string GetClassName()
virtual EntityType GetType() const override
virtual std::string GetName() const override
double GetAttributeFlyingSpeedValue() const
void SetDataIsCharging(const bool data_is_charging)
virtual ProtocolCraft::Json::Value Serialize() const override
std::map< EntityAttribute::Type, EntityAttribute > attributes
virtual ProtocolCraft::Json::Value Serialize() const override
Definition MobEntity.cpp:34
virtual void SetMetadataValue(const int index, const std::any &value) override
Definition MobEntity.cpp:49
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45