Botcraft 1.21.8
Loading...
Searching...
No Matches
AbstractBoatEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, AbstractBoatEntity::metadata_count> AbstractBoatEntity::metadata_names{ {
9 "data_id_paddle_left",
10 "data_id_paddle_right",
11 "data_id_bubble_time",
12 } };
13
15 {
16 // Initialize all metadata with default values
20 }
21
26
27
29 {
30 return true;
31 }
32
33
35 {
37
38 output["metadata"]["data_id_paddle_left"] = GetDataIdPaddleLeft();
39 output["metadata"]["data_id_paddle_right"] = GetDataIdPaddleRight();
40 output["metadata"]["data_id_bubble_time"] = GetDataIdBubbleTime();
41
42
43 return output;
44 }
45
46
47 void AbstractBoatEntity::SetMetadataValue(const int index, const std::any& value)
48 {
49 if (index < hierarchy_metadata_count)
50 {
52 }
54 {
55 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
57 }
58 }
59
61 {
62 std::shared_lock<std::shared_mutex> lock(entity_mutex);
63 return std::any_cast<bool>(metadata.at("data_id_paddle_left"));
64 }
65
67 {
68 std::shared_lock<std::shared_mutex> lock(entity_mutex);
69 return std::any_cast<bool>(metadata.at("data_id_paddle_right"));
70 }
71
73 {
74 std::shared_lock<std::shared_mutex> lock(entity_mutex);
75 return std::any_cast<int>(metadata.at("data_id_bubble_time"));
76 }
77
78
79 void AbstractBoatEntity::SetDataIdPaddleLeft(const bool data_id_paddle_left)
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
82 metadata["data_id_paddle_left"] = data_id_paddle_left;
83 }
84
85 void AbstractBoatEntity::SetDataIdPaddleRight(const bool data_id_paddle_right)
86 {
87 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
88 metadata["data_id_paddle_right"] = data_id_paddle_right;
89 }
90
91 void AbstractBoatEntity::SetDataIdBubbleTime(const int data_id_bubble_time)
92 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
94 metadata["data_id_bubble_time"] = data_id_bubble_time;
95 }
96}
97#endif
virtual void SetMetadataValue(const int index, const std::any &value) override
void SetDataIdPaddleRight(const bool data_id_paddle_right)
static const std::array< std::string, metadata_count > metadata_names
static constexpr int metadata_count
void SetDataIdBubbleTime(const int data_id_bubble_time)
virtual bool IsAbstractBoat() const override
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataIdPaddleLeft(const bool data_id_paddle_left)
static constexpr int hierarchy_metadata_count
std::shared_mutex entity_mutex
Definition Entity.hpp:261
std::map< std::string, std::any > metadata
Definition Entity.hpp:276
virtual void SetMetadataValue(const int index, const std::any &value) override
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