Botcraft 1.21.4
Loading...
Searching...
No Matches
OcelotEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, OcelotEntity::metadata_count> OcelotEntity::metadata_names{ {
8#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
9 "data_trusting",
10#else
11 "data_type_id",
12#endif
13 } };
14
16 {
17 // Initialize all metadata with default values
18#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
19 SetDataTrusting(false);
20#else
21 SetDataTypeId(0);
22#endif
23
24 // Initialize all attributes with default values
28 }
29
34
35
36 std::string OcelotEntity::GetName() const
37 {
38 return "ocelot";
39 }
40
45
46
48 {
49 return "ocelot";
50 }
51
56
57
59 {
61
62#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
63 output["metadata"]["data_trusting"] = GetDataTrusting();
64#else
65 output["metadata"]["data_type_id"] = GetDataTypeId();
66#endif
67
68 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
69
70 return output;
71 }
72
73
74 void OcelotEntity::SetMetadataValue(const int index, const std::any& value)
75 {
76 if (index < hierarchy_metadata_count)
77 {
79 }
81 {
82 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
84 }
85 }
86
87#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
89 {
90 std::shared_lock<std::shared_mutex> lock(entity_mutex);
91 return std::any_cast<bool>(metadata.at("data_trusting"));
92 }
93
94
95 void OcelotEntity::SetDataTrusting(const bool data_trusting)
96 {
97 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
98 metadata["data_trusting"] = data_trusting;
99 }
100#else
101 int OcelotEntity::GetDataTypeId() const
102 {
103 std::shared_lock<std::shared_mutex> lock(entity_mutex);
104 return std::any_cast<int>(metadata.at("data_type_id"));
105 }
106
107
108 void OcelotEntity::SetDataTypeId(const int data_type_id)
109 {
110 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
111 metadata["data_type_id"] = data_type_id;
112 }
113#endif
114
115
117 {
118 std::shared_lock<std::shared_mutex> lock(entity_mutex);
120 }
121
122
124 {
125 return 0.6;
126 }
127
129 {
130 return 0.7;
131 }
132
133}
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:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
std::map< EntityAttribute::Type, EntityAttribute > attributes
virtual ProtocolCraft::Json::Value Serialize() const override
bool GetDataTrusting() const
double GetAttributeAttackDamageValue() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
static EntityType GetClassType()
virtual EntityType GetType() const override
static constexpr int metadata_count
void SetDataTrusting(const bool data_trusting)
static const std::array< std::string, metadata_count > metadata_names
virtual double GetHeightImpl() const override
static constexpr int hierarchy_metadata_count
static std::string GetClassName()
virtual double GetWidthImpl() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45