Botcraft 1.21.4
Loading...
Searching...
No Matches
CreeperEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, CreeperEntity::metadata_count> CreeperEntity::metadata_names{ {
8 "data_swell_dir",
9 "data_is_powered",
10 "data_is_ignited",
11 } };
12
14 {
15 // Initialize all metadata with default values
17 SetDataIsPowered(false);
18 SetDataIsIgnited(false);
19
20 // Initialize all attributes with default values
22 }
23
28
29
30 std::string CreeperEntity::GetName() const
31 {
32 return "creeper";
33 }
34
39
40
42 {
43 return "creeper";
44 }
45
50
51
53 {
55
56 output["metadata"]["data_swell_dir"] = GetDataSwellDir();
57 output["metadata"]["data_is_powered"] = GetDataIsPowered();
58 output["metadata"]["data_is_ignited"] = GetDataIsIgnited();
59
60 return output;
61 }
62
63
64 void CreeperEntity::SetMetadataValue(const int index, const std::any& value)
65 {
66 if (index < hierarchy_metadata_count)
67 {
69 }
71 {
72 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
74 }
75 }
76
78 {
79 std::shared_lock<std::shared_mutex> lock(entity_mutex);
80 return std::any_cast<int>(metadata.at("data_swell_dir"));
81 }
82
84 {
85 std::shared_lock<std::shared_mutex> lock(entity_mutex);
86 return std::any_cast<bool>(metadata.at("data_is_powered"));
87 }
88
90 {
91 std::shared_lock<std::shared_mutex> lock(entity_mutex);
92 return std::any_cast<bool>(metadata.at("data_is_ignited"));
93 }
94
95
96 void CreeperEntity::SetDataSwellDir(const int data_swell_dir)
97 {
98 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
99 metadata["data_swell_dir"] = data_swell_dir;
100 }
101
102 void CreeperEntity::SetDataIsPowered(const bool data_is_powered)
103 {
104 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
105 metadata["data_is_powered"] = data_is_powered;
106 }
107
108 void CreeperEntity::SetDataIsIgnited(const bool data_is_ignited)
109 {
110 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
111 metadata["data_is_ignited"] = data_is_ignited;
112 }
113
114
116 {
117 return 0.6;
118 }
119
121 {
122 return 1.7;
123 }
124
125}
void SetDataIsIgnited(const bool data_is_ignited)
static constexpr int hierarchy_metadata_count
virtual void SetMetadataValue(const int index, const std::any &value) override
static EntityType GetClassType()
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataSwellDir(const int data_swell_dir)
static constexpr int metadata_count
virtual double GetWidthImpl() const override
virtual std::string GetName() const override
static const std::array< std::string, metadata_count > metadata_names
virtual double GetHeightImpl() const override
virtual EntityType GetType() const override
static std::string GetClassName()
void SetDataIsPowered(const bool data_is_powered)
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45