Botcraft 1.21.5
Loading...
Searching...
No Matches
AbstractHorseEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, AbstractHorseEntity::metadata_count> AbstractHorseEntity::metadata_names{ {
8 "data_id_flags",
9#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
10 "data_id_owner_uuid",
11#endif
12 } };
13
15 {
16 // Initialize all metadata with default values
18#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
19 SetDataIdOwnerUuid(std::optional<ProtocolCraft::UUID>());
20#endif
21
22 // Initialize all attributes with default values
23#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
24 attributes.insert({ EntityAttribute::Type::HorseJumpStrength, EntityAttribute(EntityAttribute::Type::HorseJumpStrength, 0.7) });
25#else
27#endif
30#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
34#endif
35 }
36
41
43 {
44 return true;
45 }
46
47
49 {
51
52 output["metadata"]["data_id_flags"] = GetDataIdFlags();
53#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
54 output["metadata"]["data_id_owner_uuid"] = GetDataIdOwnerUuid() ? ProtocolCraft::Json::Value(GetDataIdOwnerUuid().value()) : ProtocolCraft::Json::Value();
55#endif
56
57#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
58 output["attributes"]["horse.jump_strength"] = GetAttributeJumpStrengthValue();
59#endif
60
61
62 return output;
63 }
64
65
66 void AbstractHorseEntity::SetMetadataValue(const int index, const std::any& value)
67 {
68 if (index < hierarchy_metadata_count)
69 {
71 }
73 {
74 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
76 }
77 }
78
80 {
81 std::shared_lock<std::shared_mutex> lock(entity_mutex);
82 return std::any_cast<char>(metadata.at("data_id_flags"));
83 }
84
85#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
86 std::optional<ProtocolCraft::UUID> AbstractHorseEntity::GetDataIdOwnerUuid() const
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<std::optional<ProtocolCraft::UUID>>(metadata.at("data_id_owner_uuid"));
90 }
91#endif
92
93
94 void AbstractHorseEntity::SetDataIdFlags(const char data_id_flags)
95 {
96 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
97 metadata["data_id_flags"] = data_id_flags;
98 }
99
100#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
101 void AbstractHorseEntity::SetDataIdOwnerUuid(const std::optional<ProtocolCraft::UUID>& data_id_owner_uuid)
102 {
103 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
104 metadata["data_id_owner_uuid"] = data_id_owner_uuid;
105 }
106#endif
107
108
109#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
111 {
112 std::shared_lock<std::shared_mutex> lock(entity_mutex);
113 return attributes.at(EntityAttribute::Type::HorseJumpStrength).GetValue();
114 }
115#endif
116
117}
static const std::array< std::string, metadata_count > metadata_names
virtual bool IsAbstractHorse() const override
void SetDataIdFlags(const char data_id_flags)
virtual ProtocolCraft::Json::Value Serialize() const override
static constexpr int hierarchy_metadata_count
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
std::shared_mutex entity_mutex
Definition Entity.hpp:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
std::map< EntityAttribute::Type, EntityAttribute > attributes
double GetAttributeJumpStrengthValue() const
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45