Botcraft 1.21.8
Loading...
Searching...
No Matches
HangingEntity.cpp
Go to the documentation of this file.
2
4
5#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
6#include <mutex>
7#endif
8
9namespace Botcraft
10{
11#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
12 const std::array<std::string, HangingEntity::metadata_count> HangingEntity::metadata_names{ {
13 "data_direction",
14 } };
15#endif
16
18 {
19#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
20 // Initialize all metadata with default values
21 SetDataDirection(static_cast<int>(Direction::South));
22#endif
23
24 }
25
30
32 {
33 return true;
34 }
35
36
37#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
39 {
41
42 output["metadata"]["data_direction"] = GetDataDirection();
43
44 return output;
45 }
46
47 void HangingEntity::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
60
62 {
63 std::shared_lock<std::shared_mutex> lock(entity_mutex);
64 return std::any_cast<int>(metadata.at("data_direction"));
65 }
66
67
68 void HangingEntity::SetDataDirection(const int data_direction)
69 {
70 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
71 metadata["data_direction"] = data_direction;
72 }
73#endif
74
75}
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1154
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:681
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
virtual bool IsHangingEntity() const override
static constexpr int hierarchy_metadata_count
void SetDataDirection(const int data_direction)
static const std::array< std::string, metadata_count > metadata_names
static constexpr int metadata_count
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45