Botcraft 1.21.4
Loading...
Searching...
No Matches
CamelEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, CamelEntity::metadata_count> CamelEntity::metadata_names{ {
9 "dash",
10 "last_pose_change_tick",
11 } };
12
14 {
15 // Initialize all metadata with default values
16 SetDash(true);
17#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
19#else
21#endif
22
23 // Initialize all attributes with default values
26#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
27 attributes.insert({ EntityAttribute::Type::HorseJumpStrength, EntityAttribute(EntityAttribute::Type::HorseJumpStrength, 0.42) });
28#else
31#endif
32 }
33
38
39
40 std::string CamelEntity::GetName() const
41 {
42 return "camel";
43 }
44
49
50
52 {
53 return "camel";
54 }
55
60
61
63 {
65
66 output["metadata"]["dash"] = GetDash();
67 output["metadata"]["last_pose_change_tick"] = GetLastPoseChangeTick();
68
69 return output;
70 }
71
72
73 void CamelEntity::SetMetadataValue(const int index, const std::any& value)
74 {
75 if (index < hierarchy_metadata_count)
76 {
78 }
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
83 }
84 }
85
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<bool>(metadata.at("dash"));
90 }
91
93 {
94 std::shared_lock<std::shared_mutex> lock(entity_mutex);
95 return std::any_cast<long long int>(metadata.at("last_pose_change_tick"));
96 }
97
98
99 void CamelEntity::SetDash(const bool dash)
100 {
101 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
102 metadata["dash"] = dash;
103 }
104
105 void CamelEntity::SetLastPoseChangeTick(const long long int last_pose_change_tick)
106 {
107 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
108 metadata["last_pose_change_tick"] = last_pose_change_tick;
109 }
110
111
113 {
114 return 1.7;
115 }
116
118 {
119 return 2.375;
120 }
121
122}
123#endif
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual EntityType GetType() const override
virtual double GetWidthImpl() const override
virtual double GetHeightImpl() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static std::string GetClassName()
virtual std::string GetName() const override
static constexpr int hierarchy_metadata_count
void SetDash(const bool dash)
long long int GetLastPoseChangeTick() const
void SetLastPoseChangeTick(const long long int last_pose_change_tick)
virtual ProtocolCraft::Json::Value Serialize() const override
static EntityType GetClassType()
static const std::array< std::string, metadata_count > metadata_names
static constexpr int metadata_count
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
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