Botcraft 26.1.2
Loading...
Searching...
No Matches
CowEntity.cpp
Go to the documentation of this file.
2
3#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
4#include <mutex>
5#endif
6
7namespace Botcraft
8{
9#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
10 const std::array<std::string, CowEntity::metadata_count> CowEntity::metadata_names{ {
11 "data_variant_id",
12#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
13 "data_sound_variant_id",
14#endif
15 } };
16#endif
17
19 {
20#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
21 // Initialize all attributes with default values
24#endif
25#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
27#endif
28#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
30#endif
31 }
32
34 {
35
36 }
37
38
39 std::string CowEntity::GetName() const
40 {
41 return "cow";
42 }
43
45 {
46 return EntityType::Cow;
47 }
48
49
51 {
52 return "cow";
53 }
54
59
60#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
62 {
64 output["metadata"]["data_variant_id"] = GetDataVariantId();
65#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
66 output["metadata"]["data_sound_variant_id"] = GetDataSoundVariantId();
67#endif
68
69 return output;
70 }
71
72 void CowEntity::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
85
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<int>(metadata.at("data_variant_id"));
90 }
91#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
93 {
94 std::shared_lock<std::shared_mutex> lock(entity_mutex);
95 return std::any_cast<int>(metadata.at("data_sound_variant_id"));
96 }
97#endif
98
99
100 void CowEntity::SetDataVariantId(const int data_variant_id)
101 {
102 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
103 metadata["data_variant_id"] = data_variant_id;
104 }
105#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
106 void CowEntity::SetDataSoundVariantId(const int data_sound_variant_id)
107 {
108 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
109 metadata["data_sound_variant_id"] = data_sound_variant_id;
110 }
111#endif
112#endif
113
114
116 {
117 return 0.9;
118 }
119
121 {
122 return 1.4;
123 }
124
125}
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
void SetDataSoundVariantId(const int data_suond_variant_id)
static constexpr int metadata_count
Definition CowEntity.hpp:25
static std::string GetClassName()
Definition CowEntity.cpp:50
virtual EntityType GetType() const override
Definition CowEntity.cpp:44
virtual ProtocolCraft::Json::Value Serialize() const override
Definition CowEntity.cpp:61
int GetDataVariantId() const
Definition CowEntity.cpp:86
virtual double GetHeightImpl() const override
virtual std::string GetName() const override
Definition CowEntity.cpp:39
static EntityType GetClassType()
Definition CowEntity.cpp:55
virtual double GetWidthImpl() const override
static constexpr int hierarchy_metadata_count
Definition CowEntity.hpp:28
int GetDataSoundVariantId() const
Definition CowEntity.cpp:92
virtual void SetMetadataValue(const int index, const std::any &value) override
Definition CowEntity.cpp:72
void SetDataVariantId(const int data_variant_id)
static const std::array< std::string, metadata_count > metadata_names
Definition CowEntity.hpp:27
std::shared_mutex entity_mutex
Definition Entity.hpp:267
std::map< std::string, std::any > metadata
Definition Entity.hpp:282
std::map< EntityAttribute::Type, EntityAttribute > attributes
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45