Botcraft 1.21.4
Loading...
Searching...
No Matches
BoatEntity.cpp
Go to the documentation of this file.
2
3#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
4#include <mutex>
5#endif
6
7namespace Botcraft
8{
9#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
10 const std::array<std::string, BoatEntity::metadata_count> BoatEntity::metadata_names{ {
11#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
12 "data_id_hurt",
13 "data_id_hurtdir",
14 "data_id_damage",
15#endif
16 "data_id_type",
17 "data_id_paddle_left",
18 "data_id_paddle_right",
19#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
20 "data_id_bubble_time",
21#endif
22 } };
23#endif
24
25#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
27#else
28 BoatEntity::BoatEntity(const EntityType type) : type(type)
29#endif
30 {
31 // Initialize all metadata with default values
32#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
35 SetDataIdDamage(0.0f);
36#endif
37#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
38 SetDataIdType(0);
41#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
43#endif
44#endif
45 }
46
51
52
53 std::string BoatEntity::GetName() const
54 {
55 return "boat";
56 }
57
59 {
60#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
61 return EntityType::Boat;
62#else
63 return type;
64#endif
65 }
66
67
69 {
70 return "boat";
71 }
72
73#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
74 EntityType BoatEntity::GetClassType()
75 {
76 return EntityType::Boat;
77 }
78#else
79 bool BoatEntity::IsBoat() const
80 {
81 return true;
82 }
83#endif
84
85
87 {
88#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
90#elif PROTOCOL_VERSION < 768 /* < 1.21.2 */
92#else
94#endif
95
96#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
97#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
98 output["metadata"]["data_id_hurt"] = GetDataIdHurt();
99 output["metadata"]["data_id_hurtdir"] = GetDataIdHurtdir();
100 output["metadata"]["data_id_damage"] = GetDataIdDamage();
101#endif
102 output["metadata"]["data_id_type"] = GetDataIdType();
103 output["metadata"]["data_id_paddle_left"] = GetDataIdPaddleLeft();
104 output["metadata"]["data_id_paddle_right"] = GetDataIdPaddleRight();
105#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
106 output["metadata"]["data_id_bubble_time"] = GetDataIdBubbleTime();
107#endif
108#else
109 output["type"] = type;
110#endif
111
112 return output;
113 }
114
115
116#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
117 void BoatEntity::SetMetadataValue(const int index, const std::any& value)
118 {
119 if (index < hierarchy_metadata_count)
120 {
121#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
122 Entity::SetMetadataValue(index, value);
123#else
125#endif
126 }
127 else if (index - hierarchy_metadata_count < metadata_count)
128 {
129 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
131 }
132 }
133
134#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
135 int BoatEntity::GetDataIdHurt() const
136 {
137 std::shared_lock<std::shared_mutex> lock(entity_mutex);
138 return std::any_cast<int>(metadata.at("data_id_hurt"));
139 }
140
142 {
143 std::shared_lock<std::shared_mutex> lock(entity_mutex);
144 return std::any_cast<int>(metadata.at("data_id_hurtdir"));
145 }
146
147 float BoatEntity::GetDataIdDamage() const
148 {
149 std::shared_lock<std::shared_mutex> lock(entity_mutex);
150 return std::any_cast<float>(metadata.at("data_id_damage"));
151 }
152#endif
153
154 int BoatEntity::GetDataIdType() const
155 {
156 std::shared_lock<std::shared_mutex> lock(entity_mutex);
157 return std::any_cast<int>(metadata.at("data_id_type"));
158 }
159
161 {
162 std::shared_lock<std::shared_mutex> lock(entity_mutex);
163 return std::any_cast<bool>(metadata.at("data_id_paddle_left"));
164 }
165
167 {
168 std::shared_lock<std::shared_mutex> lock(entity_mutex);
169 return std::any_cast<bool>(metadata.at("data_id_paddle_right"));
170 }
171
172#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
174 {
175 std::shared_lock<std::shared_mutex> lock(entity_mutex);
176 return std::any_cast<int>(metadata.at("data_id_bubble_time"));
177 }
178#endif
179
180
181#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
182 void BoatEntity::SetDataIdHurt(const int data_id_hurt)
183 {
184 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
185 metadata["data_id_hurt"] = data_id_hurt;
186 }
187
188 void BoatEntity::SetDataIdHurtdir(const int data_id_hurtdir)
189 {
190 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
191 metadata["data_id_hurtdir"] = data_id_hurtdir;
192 }
193
194 void BoatEntity::SetDataIdDamage(const float data_id_damage)
195 {
196 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
197 metadata["data_id_damage"] = data_id_damage;
198 }
199#endif
200
201 void BoatEntity::SetDataIdType(const int data_id_type)
202 {
203 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
204 metadata["data_id_type"] = data_id_type;
205 }
206
207 void BoatEntity::SetDataIdPaddleLeft(const bool data_id_paddle_left)
208 {
209 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
210 metadata["data_id_paddle_left"] = data_id_paddle_left;
211 }
212
213 void BoatEntity::SetDataIdPaddleRight(const bool data_id_paddle_right)
214 {
215 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
216 metadata["data_id_paddle_right"] = data_id_paddle_right;
217 }
218
219#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
220 void BoatEntity::SetDataIdBubbleTime(const int data_id_bubble_time)
221 {
222 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
223 metadata["data_id_bubble_time"] = data_id_bubble_time;
224 }
225#endif
226#endif
227
228
230 {
231 return 1.375;
232 }
233
235 {
236 return 0.5625;
237 }
238
239}
void SetDataIdPaddleRight(const bool data_id_paddle_right)
static const std::array< std::string, metadata_count > metadata_names
void SetDataIdBubbleTime(const int data_id_bubble_time)
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataIdPaddleLeft(const bool data_id_paddle_left)
virtual double GetWidthImpl() const override
BoatEntity(const EntityType type)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual EntityType GetType() const override
static std::string GetClassName()
virtual double GetHeightImpl() const override
const EntityType type
virtual bool IsBoat() const override
static constexpr int hierarchy_metadata_count
virtual std::string GetName() const override
static constexpr int metadata_count
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1095
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
static const std::array< std::string, metadata_count > metadata_names
Definition Entity.hpp:61
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
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