Botcraft 26.3
Loading...
Searching...
No Matches
AbstractHorseEntity.cpp
Go to the documentation of this file.
2
3namespace Botcraft
4{
6 {
7 // Initialize all metadata with default values
10#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
11 SetDataIdOwnerUuid(std::optional<ProtocolCraft::UUID>());
12#endif
13
14 // Initialize all attributes with default values
15#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
16 attributes.insert({ EntityAttribute::Type::HorseJumpStrength, EntityAttribute(EntityAttribute::Type::HorseJumpStrength, 0.7) });
17#else
19#endif
22#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
26#endif
27 }
28
33
35 {
36 return true;
37 }
38
39
41 {
43
44 output["metadata"]["data_id_flags"] = GetDataIdFlags();
45#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
46 output["metadata"]["data_id_owner_uuid"] = GetDataIdOwnerUuid() ? ProtocolCraft::Json::Value(GetDataIdOwnerUuid().value()) : ProtocolCraft::Json::Value();
47#endif
48
49#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
50 output["attributes"]["horse.jump_strength"] = GetAttributeJumpStrengthValue();
51#endif
52
53
54 return output;
55 }
56
57
59 {
60 return GetMetadata<char>(BOTCRAFT_ENTITY_METADATA_INDEX("data_id_flags"));
61 }
62
63#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
64 std::optional<ProtocolCraft::UUID> AbstractHorseEntity::GetDataIdOwnerUuid() const
65 {
66 return GetMetadata<std::optional<ProtocolCraft::UUID>>(BOTCRAFT_ENTITY_METADATA_INDEX("data_id_owner_uuid"));
67 }
68#endif
69
70
71 void AbstractHorseEntity::SetDataIdFlags(const char data_id_flags)
72 {
73 SetMetadata(BOTCRAFT_ENTITY_METADATA_INDEX("data_id_flags"), data_id_flags);
74 }
75
76#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
77 void AbstractHorseEntity::SetDataIdOwnerUuid(const std::optional<ProtocolCraft::UUID>& data_id_owner_uuid)
78 {
79 SetMetadata(BOTCRAFT_ENTITY_METADATA_INDEX("data_id_owner_uuid"), data_id_owner_uuid);
80 }
81#endif
82
83
84#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
86 {
87 std::shared_lock<std::shared_mutex> lock(entity_mutex);
88 return attributes.at(EntityAttribute::Type::HorseJumpStrength).GetValue();
89 }
90#endif
91
92}
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 ProtocolCraft::Json::Value Serialize() const override
void SetMetadata(const int index, const std::any &value)
Definition Entity.cpp:366
std::shared_mutex entity_mutex
Definition Entity.hpp:320
std::vector< std::any > metadata
Definition Entity.hpp:335
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
#define BOTCRAFT_ENTITY_METADATA_INDEX(name)
Definition Entity.hpp:347