Botcraft 1.21.5
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#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
12 "data_saddle_id",
13#endif
14 } };
15
17 {
18 // Initialize all metadata with default values
20 SetDataSuffocating(false);
21#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
22 SetDataSaddleId(false);
23#endif
24
25 // Initialize all attributes with default values
27#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
29#endif
30 }
31
36
37
38 std::string StriderEntity::GetName() const
39 {
40 return "strider";
41 }
42
47
48
50 {
51 return "strider";
52 }
53
58
59
61 {
63
64 output["metadata"]["data_boost_time"] = GetDataBoostTime();
65 output["metadata"]["data_suffocating"] = GetDataSuffocating();
66#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
67 output["metadata"]["data_saddle_id"] = GetDataSaddleId();
68#endif
69
70 return output;
71 }
72
73
74 void StriderEntity::SetMetadataValue(const int index, const std::any& value)
75 {
76 if (index < hierarchy_metadata_count)
77 {
79 }
81 {
82 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
84 }
85 }
86
88 {
89 std::shared_lock<std::shared_mutex> lock(entity_mutex);
90 return std::any_cast<int>(metadata.at("data_boost_time"));
91 }
92
94 {
95 std::shared_lock<std::shared_mutex> lock(entity_mutex);
96 return std::any_cast<bool>(metadata.at("data_suffocating"));
97 }
98
99#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
100 bool StriderEntity::GetDataSaddleId() const
101 {
102 std::shared_lock<std::shared_mutex> lock(entity_mutex);
103 return std::any_cast<bool>(metadata.at("data_saddle_id"));
104 }
105#endif
106
107
108 void StriderEntity::SetDataBoostTime(const int data_boost_time)
109 {
110 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
111 metadata["data_boost_time"] = data_boost_time;
112 }
113
114 void StriderEntity::SetDataSuffocating(const bool data_suffocating)
115 {
116 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
117 metadata["data_suffocating"] = data_suffocating;
118 }
119
120#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
121 void StriderEntity::SetDataSaddleId(const bool data_saddle_id)
122 {
123 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
124 metadata["data_saddle_id"] = data_saddle_id;
125 }
126#endif
127
128
130 {
131 return 0.9;
132 }
133
135 {
136 return 1.7;
137 }
138
139}
140#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:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45