Botcraft 1.21.4
Loading...
Searching...
No Matches
AbstractArrowEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, AbstractArrowEntity::metadata_count> AbstractArrowEntity::metadata_names{ {
8 "id_flags",
9#if PROTOCOL_VERSION < 579 /* < 1.16 */ && PROTOCOL_VERSION > 393 /* > 1.13 */
10 "data_owneruuid_id",
11#endif
12#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
13 "pierce_level",
14#endif
15#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
16 "in_ground",
17#endif
18 } };
19
21 {
22 // Initialize all metadata with default values
23 SetIdFlags(0);
24#if PROTOCOL_VERSION < 579 /* < 1.16 */ && PROTOCOL_VERSION > 393 /* > 1.13 */
25 SetDataOwneruuidId(std::optional<ProtocolCraft::UUID>());
26#endif
27#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
29#endif
30#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
31 SetInGround(false);
32#endif
33 }
34
39
41 {
42 return true;
43 }
44
45
47 {
48#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
50#else
52#endif
53
54 output["metadata"]["id_flags"] = GetIdFlags();
55#if PROTOCOL_VERSION < 579 /* < 1.16 */ && PROTOCOL_VERSION > 393 /* > 1.13 */
56 output["metadata"]["data_owneruuid_id"] = GetDataOwneruuidId() ? ProtocolCraft::Json::Value(GetDataOwneruuidId().value()) : ProtocolCraft::Json::Value();
57#endif
58#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
59 output["metadata"]["pierce_level"] = GetPierceLevel();
60#endif
61#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
62 output["metadata"]["in_ground"] = GetInGround();
63#endif
64
65 return output;
66 }
67
68
69 void AbstractArrowEntity::SetMetadataValue(const int index, const std::any& value)
70 {
71 if (index < hierarchy_metadata_count)
72 {
73#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
75#else
76 Entity::SetMetadataValue(index, value);
77#endif
78 }
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
83 }
84 }
85
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<char>(metadata.at("id_flags"));
90 }
91
92#if PROTOCOL_VERSION < 579 /* < 1.16 */ && PROTOCOL_VERSION > 393 /* > 1.13 */
93 std::optional<ProtocolCraft::UUID> AbstractArrowEntity::GetDataOwneruuidId() const
94 {
95 std::shared_lock<std::shared_mutex> lock(entity_mutex);
96 return std::any_cast<std::optional<ProtocolCraft::UUID>>(metadata.at("data_owneruuid_id"));
97 }
98#endif
99
100#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
102 {
103 std::shared_lock<std::shared_mutex> lock(entity_mutex);
104 return std::any_cast<char>(metadata.at("pierce_level"));
105 }
106#endif
107
108#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
110 {
111 std::shared_lock<std::shared_mutex> lock(entity_mutex);
112 return std::any_cast<bool>(metadata.at("in_ground"));
113 }
114#endif
115
116
117 void AbstractArrowEntity::SetIdFlags(const char id_flags)
118 {
119 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
120 metadata["id_flags"] = id_flags;
121 }
122
123#if PROTOCOL_VERSION < 579 /* < 1.16 */ && PROTOCOL_VERSION > 393 /* > 1.13 */
124 void AbstractArrowEntity::SetDataOwneruuidId(const std::optional<ProtocolCraft::UUID>& data_owneruuid_id)
125 {
126 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
127 metadata["data_owneruuid_id"] = data_owneruuid_id;
128 }
129#endif
130
131#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
132 void AbstractArrowEntity::SetPierceLevel(const char pierce_level)
133 {
134 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
135 metadata["pierce_level"] = pierce_level;
136 }
137#endif
138
139#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
140 void AbstractArrowEntity::SetInGround(const bool in_ground)
141 {
142 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
143 metadata["in_ground"] = in_ground;
144 }
145#endif
146
147}
void SetInGround(const bool in_ground)
virtual void SetMetadataValue(const int index, const std::any &value) override
void SetIdFlags(const char id_flags)
virtual bool IsAbstractArrow() const override
static constexpr int hierarchy_metadata_count
static const std::array< std::string, metadata_count > metadata_names
virtual ProtocolCraft::Json::Value Serialize() const override
void SetPierceLevel(const char pierce_level)
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1095
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45