Botcraft 1.21.10
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
58 {
59 std::shared_lock<std::shared_mutex> lock(entity_mutex);
60 return std::any_cast<char>(metadata.at("data_player_main_hand"));
61 }
62
64 {
65 std::shared_lock<std::shared_mutex> lock(entity_mutex);
66 return std::any_cast<char>(metadata.at("data_player_mode_customisation"));
67 }
68
69
70 void AvatarEntity::SetDataPlayerMainHand(const char data_player_main_hand)
71 {
72 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
73 metadata["data_player_main_hand"] = data_player_main_hand;
74 }
75
76 void AvatarEntity::SetDataPlayerModeCustomisation(const char data_player_mode_customisation)
77 {
78 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
79 metadata["data_player_mode_customisation"] = data_player_mode_customisation;
80 }
81
82}
83#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 SetDataPlayerMainHand(const char data_player_main_hand)
void SetDataPlayerModeCustomisation(const char data_player_mode_customisation)
char GetDataPlayerMainHand() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual bool IsAvatar() const override
std::shared_mutex entity_mutex
Definition Entity.hpp:264
std::map< std::string, std::any > metadata
Definition Entity.hpp:279
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