Botcraft 1.21.4
Loading...
Searching...
No Matches
StriderEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, StriderEntity::metadata_count> StriderEntity::metadata_names{ {
9 "data_boost_time",
10 "data_suffocating",
11 "data_saddle_id",
12 } };
13
15 {
16 // Initialize all metadata with default values
18 SetDataSuffocating(false);
19 SetDataSaddleId(false);
20
21 // Initialize all attributes with default values
23#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
25#endif
26 }
27
32
33
34 std::string StriderEntity::GetName() const
35 {
36 return "strider";
37 }
38
43
44
46 {
47 return "strider";
48 }
49
54
55
57 {
59
60 output["metadata"]["data_boost_time"] = GetDataBoostTime();
61 output["metadata"]["data_suffocating"] = GetDataSuffocating();
62 output["metadata"]["data_saddle_id"] = GetDataSaddleId();
63
64 return output;
65 }
66
67
68 void StriderEntity::SetMetadataValue(const int index, const std::any& value)
69 {
70 if (index < hierarchy_metadata_count)
71 {
73 }
75 {
76 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
78 }
79 }
80
82 {
83 std::shared_lock<std::shared_mutex> lock(entity_mutex);
84 return std::any_cast<int>(metadata.at("data_boost_time"));
85 }
86
88 {
89 std::shared_lock<std::shared_mutex> lock(entity_mutex);
90 return std::any_cast<bool>(metadata.at("data_suffocating"));
91 }
92
94 {
95 std::shared_lock<std::shared_mutex> lock(entity_mutex);
96 return std::any_cast<bool>(metadata.at("data_saddle_id"));
97 }
98
99
100 void StriderEntity::SetDataBoostTime(const int data_boost_time)
101 {
102 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
103 metadata["data_boost_time"] = data_boost_time;
104 }
105
106 void StriderEntity::SetDataSuffocating(const bool data_suffocating)
107 {
108 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
109 metadata["data_suffocating"] = data_suffocating;
110 }
111
112 void StriderEntity::SetDataSaddleId(const bool data_saddle_id)
113 {
114 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
115 metadata["data_saddle_id"] = data_saddle_id;
116 }
117
118
120 {
121 return 0.9;
122 }
123
125 {
126 return 1.7;
127 }
128
129}
130#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
virtual void SetMetadataValue(const int index, const std::any &value) override
static EntityType GetClassType()
virtual EntityType GetType() const override
static const std::array< std::string, metadata_count > metadata_names
bool GetDataSuffocating() const
virtual ProtocolCraft::Json::Value Serialize() const override
static constexpr int metadata_count
static constexpr int hierarchy_metadata_count
void SetDataBoostTime(const int data_boost_time)
static std::string GetClassName()
virtual double GetHeightImpl() const override
virtual double GetWidthImpl() const override
void SetDataSuffocating(const bool data_suffocating)
virtual std::string GetName() const override
void SetDataSaddleId(const bool data_saddle_id)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45