Botcraft 1.21.5
Loading...
Searching...
No Matches
MushroomCowEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
8 const std::array<std::string, MushroomCowEntity::metadata_count> MushroomCowEntity::metadata_names{ {
9 "data_type",
10 } };
11#endif
12
14 {
15#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
16 // Initialize all metadata with default values
17#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
18 SetDataType("red");
19#else
20 SetDataType(0);
21#endif
22#endif
23 }
24
29
30
31 std::string MushroomCowEntity::GetName() const
32 {
33 return "mooshroom";
34 }
35
40
41
43 {
44 return "mooshroom";
45 }
46
51
52
53#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
55 {
56#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
58#else
60#endif
61
62 output["metadata"]["data_type"] = GetDataType();
63
64 return output;
65 }
66
67
68 void MushroomCowEntity::SetMetadataValue(const int index, const std::any& value)
69 {
70 if (index < hierarchy_metadata_count)
71 {
72#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
73 CowEntity::SetMetadataValue(index, value);
74#else
76#endif
77 }
79 {
80 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
82 }
83 }
84
85#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
86 std::string MushroomCowEntity::GetDataType() const
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<std::string>(metadata.at("data_type"));
90 }
91
92
93 void MushroomCowEntity::SetDataType(const std::string& data_type)
94 {
95 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
96 metadata["data_type"] = data_type;
97 }
98#else
100 {
101 std::shared_lock<std::shared_mutex> lock(entity_mutex);
102 return std::any_cast<int>(metadata.at("data_type"));
103 }
104
105
106 void MushroomCowEntity::SetDataType(const int data_type)
107 {
108 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
109 metadata["data_type"] = data_type;
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
virtual ProtocolCraft::Json::Value Serialize() const override
Definition CowEntity.cpp:54
virtual void SetMetadataValue(const int index, const std::any &value) override
Definition CowEntity.cpp:62
std::shared_mutex entity_mutex
Definition Entity.hpp:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
virtual double GetWidthImpl() const override
virtual EntityType GetType() const override
void SetDataType(const int data_type)
virtual double GetHeightImpl() const override
virtual std::string GetName() const override
static constexpr int hierarchy_metadata_count
static std::string GetClassName()
static const std::array< std::string, metadata_count > metadata_names
virtual void SetMetadataValue(const int index, const std::any &value) override
static constexpr int metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45