Botcraft 1.21.5
Loading...
Searching...
No Matches
AbstractMinecartEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, AbstractMinecartEntity::metadata_count> AbstractMinecartEntity::metadata_names{ {
8#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
9 "data_id_hurt",
10 "data_id_hurtdir",
11 "data_id_damage",
12#endif
13#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
14 "data_id_display_block",
15#else
16 "data_id_custom_display_block",
17#endif
18 "data_id_display_offset",
19#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
20 "data_id_custom_display",
21#endif
22 } };
23
25 {
26 // Initialize all metadata with default values
27#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
30 SetDataIdDamage(0.0f);
31#endif
32#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
33 SetDataIdDisplayBlock(0);
34#else
36#endif
38#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
39 SetDataIdCustomDisplay(false);
40#endif
41 }
42
47
49 {
50 return true;
51 }
52
53
55 {
56#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
58#else
60#endif
61
62#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
63 output["metadata"]["data_id_hurt"] = GetDataIdHurt();
64 output["metadata"]["data_id_hurtdir"] = GetDataIdHurtdir();
65 output["metadata"]["data_id_damage"] = GetDataIdDamage();
66#endif
67#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
68 output["metadata"]["data_id_display_block"] = GetDataIdDisplayBlock();
69#else
70 output["metadata"]["data_id_custom_display_block"] = GetDataIdCustomDisplayBlock();
71#endif
72 output["metadata"]["data_id_display_offset"] = GetDataIdDisplayOffset();
73#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
74 output["metadata"]["data_id_custom_display"] = GetDataIdCustomDisplay();
75#endif
76
77 return output;
78 }
79
80
81 void AbstractMinecartEntity::SetMetadataValue(const int index, const std::any& value)
82 {
83 if (index < hierarchy_metadata_count)
84 {
85#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
86 Entity::SetMetadataValue(index, value);
87#else
89#endif
90 }
92 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 }
96 }
97
98#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
100 {
101 std::shared_lock<std::shared_mutex> lock(entity_mutex);
102 return std::any_cast<int>(metadata.at("data_id_hurt"));
103 }
104
106 {
107 std::shared_lock<std::shared_mutex> lock(entity_mutex);
108 return std::any_cast<int>(metadata.at("data_id_hurtdir"));
109 }
110
112 {
113 std::shared_lock<std::shared_mutex> lock(entity_mutex);
114 return std::any_cast<float>(metadata.at("data_id_damage"));
115 }
116#endif
117
118#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
119 int AbstractMinecartEntity::GetDataIdDisplayBlock() const
120 {
121 std::shared_lock<std::shared_mutex> lock(entity_mutex);
122 return std::any_cast<int>(metadata.at("data_id_display_block"));
123 }
124#else
126 {
127 std::shared_lock<std::shared_mutex> lock(entity_mutex);
128 return std::any_cast<int>(metadata.at("data_id_custom_display_block"));
129 }
130#endif
131
133 {
134 std::shared_lock<std::shared_mutex> lock(entity_mutex);
135 return std::any_cast<int>(metadata.at("data_id_display_offset"));
136 }
137
138#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
139 bool AbstractMinecartEntity::GetDataIdCustomDisplay() const
140 {
141 std::shared_lock<std::shared_mutex> lock(entity_mutex);
142 return std::any_cast<bool>(metadata.at("data_id_custom_display"));
143 }
144#endif
145
146
147#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
148 void AbstractMinecartEntity::SetDataIdHurt(const int data_id_hurt)
149 {
150 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
151 metadata["data_id_hurt"] = data_id_hurt;
152 }
153
154 void AbstractMinecartEntity::SetDataIdHurtdir(const int data_id_hurtdir)
155 {
156 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
157 metadata["data_id_hurtdir"] = data_id_hurtdir;
158 }
159
160 void AbstractMinecartEntity::SetDataIdDamage(const float data_id_damage)
161 {
162 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
163 metadata["data_id_damage"] = data_id_damage;
164 }
165#endif
166
167#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
168 void AbstractMinecartEntity::SetDataIdDisplayBlock(const int data_id_display_block)
169 {
170 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
171 metadata["data_id_display_block"] = data_id_display_block;
172 }
173#else
174 void AbstractMinecartEntity::SetDataIdCustomDisplayBlock(const int data_id_custom_display_block)
175 {
176 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
177 metadata["data_id_custom_display_block"] = data_id_custom_display_block;
178 }
179#endif
180
181 void AbstractMinecartEntity::SetDataIdDisplayOffset(const int data_id_display_offset)
182 {
183 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
184 metadata["data_id_display_offset"] = data_id_display_offset;
185 }
186
187#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
188 void AbstractMinecartEntity::SetDataIdCustomDisplay(const bool data_id_custom_display)
189 {
190 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
191 metadata["data_id_custom_display"] = data_id_custom_display;
192 }
193#endif
194
195}
virtual bool IsAbstractMinecart() const override
void SetDataIdDisplayOffset(const int data_id_display_offset)
void SetDataIdCustomDisplayBlock(const int data_id_display_block)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static const std::array< std::string, metadata_count > metadata_names
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1151
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:678
std::shared_mutex entity_mutex
Definition Entity.hpp:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
void SetDataIdHurt(const int data_id_hurt)
void SetDataIdDamage(const float data_id_damage)
float GetDataIdDamage() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataIdHurtdir(const int data_id_hurtdir)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45