Botcraft 1.21.11
Loading...
Searching...
No Matches
AvatarEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, AvatarEntity::metadata_count> AvatarEntity::metadata_names{ {
9 "data_player_main_hand",
10 "data_player_mode_customisation",
11 } };
12
14 {
15 // Initialize all metadata with default values
18 }
19
24
26 {
27 return true;
28 }
29
30
31
33 {
35
36 output["metadata"]["data_player_main_hand"] = GetDataPlayerMainHand();
37 output["metadata"]["data_player_mode_customisation"] = GetDataPlayerModeCustomisation();
38
39 return output;
40 }
41
42
43 void AvatarEntity::SetMetadataValue(const int index, const std::any& value)
44 {
45 if (index < hierarchy_metadata_count)
46 {
48 }
50 {
51 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
53 }
54 }
55
56
57#if PROTOCOL_VERSION < 774 /* < 1.21.11 */
59 {
60 std::shared_lock<std::shared_mutex> lock(entity_mutex);
61 return std::any_cast<char>(metadata.at("data_player_main_hand"));
62 }
63#else
65 {
66 std::shared_lock<std::shared_mutex> lock(entity_mutex);
67 return std::any_cast<int>(metadata.at("data_player_main_hand"));
68 }
69#endif
70
72 {
73 std::shared_lock<std::shared_mutex> lock(entity_mutex);
74 return std::any_cast<char>(metadata.at("data_player_mode_customisation"));
75 }
76
77
78#if PROTOCOL_VERSION < 774 /* < 1.21.11 */
79 void AvatarEntity::SetDataPlayerMainHand(const char data_player_main_hand)
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
82 metadata["data_player_main_hand"] = data_player_main_hand;
83 }
84#else
85 void AvatarEntity::SetDataPlayerMainHand(const int data_player_main_hand)
86 {
87 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
88 metadata["data_player_main_hand"] = data_player_main_hand;
89 }
90#endif
91
92 void AvatarEntity::SetDataPlayerModeCustomisation(const char data_player_mode_customisation)
93 {
94 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 metadata["data_player_mode_customisation"] = data_player_mode_customisation;
96 }
97
98}
99#endif
static constexpr int metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
char GetDataPlayerModeCustomisation() const
static const std::array< std::string, metadata_count > metadata_names
static constexpr int hierarchy_metadata_count
void SetDataPlayerModeCustomisation(const char data_player_mode_customisation)
virtual void SetMetadataValue(const int index, const std::any &value) override
int GetDataPlayerMainHand() const
virtual bool IsAvatar() const override
void SetDataPlayerMainHand(const int data_player_main_hand)
std::shared_mutex entity_mutex
Definition Entity.hpp:267
std::map< std::string, std::any > metadata
Definition Entity.hpp:282
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45