Botcraft 1.21.4
Loading...
Searching...
No Matches
LlamaEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, LlamaEntity::metadata_count> LlamaEntity::metadata_names{ {
8 "data_strength_id",
9#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
10 "data_swag_id",
11#endif
12 "data_variant_id",
13 } };
14
16 {
17 // Initialize all metadata with default values
19#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
20 SetDataSwagId(-1);
21#endif
23
24 // Initialize all attributes with default values
25#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
27#endif
28 }
29
34
35
36 std::string LlamaEntity::GetName() const
37 {
38 return "llama";
39 }
40
45
46
48 {
49 return "llama";
50 }
51
56
57
59 {
61
62 output["metadata"]["data_strength_id"] = GetDataStrengthId();
63#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
64 output["metadata"]["data_swag_id"] = GetDataSwagId();
65#endif
66 output["metadata"]["data_variant_id"] = GetDataVariantId();
67
68 return output;
69 }
70
71
72 void LlamaEntity::SetMetadataValue(const int index, const std::any& value)
73 {
74 if (index < hierarchy_metadata_count)
75 {
77 }
79 {
80 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
82 }
83 }
84
86 {
87 std::shared_lock<std::shared_mutex> lock(entity_mutex);
88 return std::any_cast<int>(metadata.at("data_strength_id"));
89 }
90
91#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
92 int LlamaEntity::GetDataSwagId() const
93 {
94 std::shared_lock<std::shared_mutex> lock(entity_mutex);
95 return std::any_cast<int>(metadata.at("data_swag_id"));
96 }
97#endif
98
100 {
101 std::shared_lock<std::shared_mutex> lock(entity_mutex);
102 return std::any_cast<int>(metadata.at("data_variant_id"));
103 }
104
105
106 void LlamaEntity::SetDataStrengthId(const int data_strength_id)
107 {
108 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
109 metadata["data_strength_id"] = data_strength_id;
110 }
111
112#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
113 void LlamaEntity::SetDataSwagId(const int data_swag_id)
114 {
115 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
116 metadata["data_swag_id"] = data_swag_id;
117 }
118#endif
119
120 void LlamaEntity::SetDataVariantId(const int data_variant_id)
121 {
122 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
123 metadata["data_variant_id"] = data_variant_id;
124 }
125
126
128 {
129 return 0.9;
130 }
131
133 {
134 return 1.87;
135 }
136
137}
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
std::map< EntityAttribute::Type, EntityAttribute > attributes
static std::string GetClassName()
static EntityType GetClassType()
int GetDataVariantId() const
virtual std::string GetName() const override
static constexpr int metadata_count
void SetDataVariantId(const int data_variant_id)
static constexpr int hierarchy_metadata_count
void SetDataStrengthId(const int data_strength_id)
int GetDataStrengthId() const
virtual ProtocolCraft::Json::Value Serialize() const override
virtual EntityType GetType() const override
static const std::array< std::string, metadata_count > metadata_names
virtual double GetWidthImpl() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual double GetHeightImpl() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45