Botcraft 1.21.4
Loading...
Searching...
No Matches
HorseEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, HorseEntity::metadata_count> HorseEntity::metadata_names{ {
8 "data_id_type_variant",
9#if PROTOCOL_VERSION < 405 /* < 1.14 */
10 "armor_type",
11#endif
12 } };
13
15 {
16 // Initialize all metadata with default values
18#if PROTOCOL_VERSION < 405 /* < 1.14 */
19 SetArmorType(std::optional<int>());
20#endif
21 }
22
27
28
29 std::string HorseEntity::GetName() const
30 {
31 return "horse";
32 }
33
38
39
41 {
42 return "horse";
43 }
44
49
50
52 {
54
55 output["metadata"]["data_id_type_variant"] = GetDataIdTypeVariant();
56#if PROTOCOL_VERSION < 405 /* < 1.14 */
57 output["metadata"]["armor_type"] = GetArmorType() ? ProtocolCraft::Json::Value(GetArmorType().value()) : ProtocolCraft::Json::Value();
58#endif
59
60 return output;
61 }
62
63
64 void HorseEntity::SetMetadataValue(const int index, const std::any& value)
65 {
66 if (index < hierarchy_metadata_count)
67 {
69 }
71 {
72 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
74 }
75 }
76
78 {
79 std::shared_lock<std::shared_mutex> lock(entity_mutex);
80 return std::any_cast<int>(metadata.at("data_id_type_variant"));
81 }
82
83#if PROTOCOL_VERSION < 405 /* < 1.14 */
84 std::optional<int> HorseEntity::GetArmorType() const
85 {
86 std::shared_lock<std::shared_mutex> lock(entity_mutex);
87 return std::any_cast<std::optional<int>>(metadata.at("armor_type"));
88 }
89#endif
90
91
92 void HorseEntity::SetDataIdTypeVariant(const int data_id_type_variant)
93 {
94 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 metadata["data_id_type_variant"] = data_id_type_variant;
96 }
97
98#if PROTOCOL_VERSION < 405 /* < 1.14 */
99 void HorseEntity::SetArmorType(const std::optional<int>& armor_type)
100 {
101 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
102 metadata["armor_type"] = armor_type;
103 }
104#endif
105
106
108 {
109 return 1.3964844;
110 }
111
113 {
114 return 1.6;
115 }
116
117}
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
int GetDataIdTypeVariant() const
static constexpr int hierarchy_metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
static EntityType GetClassType()
virtual void SetMetadataValue(const int index, const std::any &value) override
static std::string GetClassName()
static constexpr int metadata_count
virtual double GetWidthImpl() const override
virtual double GetHeightImpl() const override
virtual std::string GetName() const override
virtual EntityType GetType() const override
void SetDataIdTypeVariant(const int data_id_type_variant)
static const std::array< std::string, metadata_count > metadata_names
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45