Botcraft 1.21.4
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 {
56 }
57 }
58
60 {
61 std::shared_lock<std::shared_mutex> lock(entity_mutex);
62 return std::any_cast<bool>(metadata.at("data_id_paddle_left"));
63 }
64
66 {
67 std::shared_lock<std::shared_mutex> lock(entity_mutex);
68 return std::any_cast<bool>(metadata.at("data_id_paddle_right"));
69 }
70
72 {
73 std::shared_lock<std::shared_mutex> lock(entity_mutex);
74 return std::any_cast<int>(metadata.at("data_id_bubble_time"));
75 }
76
77
78 void AbstractBoatEntity::SetDataIdPaddleLeft(const bool data_id_paddle_left)
79 {
80 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
81 metadata["data_id_paddle_left"] = data_id_paddle_left;
82 }
83
84 void AbstractBoatEntity::SetDataIdPaddleRight(const bool data_id_paddle_right)
85 {
86 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
87 metadata["data_id_paddle_right"] = data_id_paddle_right;
88 }
89
90 void AbstractBoatEntity::SetDataIdBubbleTime(const int data_id_bubble_time)
91 {
92 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
93 metadata["data_id_bubble_time"] = data_id_bubble_time;
94 }
95}
96#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:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
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