Botcraft 1.21.4
Loading...
Searching...
No Matches
FrogEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, FrogEntity::metadata_count> FrogEntity::metadata_names{ {
9 "data_variant_id",
10 "data_tongue_target_id",
11 } };
12
14 {
15 // Initialize all metadata with default values
17 SetDataTongueTargetId(std::optional<int>());
18
19 // Initialize all attributes with default values
23#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
25#endif
26 }
27
32
33
34 std::string FrogEntity::GetName() const
35 {
36 return "frog";
37 }
38
40 {
41 return EntityType::Frog;
42 }
43
44
46 {
47 return "frog";
48 }
49
54
55
57 {
59
60 output["metadata"]["data_variant_id"] = GetDataVariantId();
61 output["metadata"]["data_tongue_target_id"] = GetDataTongueTargetId() ? ProtocolCraft::Json::Value(GetDataTongueTargetId().value()) : ProtocolCraft::Json::Value();
62
63 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
64
65 return output;
66 }
67
68
69 void FrogEntity::SetMetadataValue(const int index, const std::any& value)
70 {
71 if (index < hierarchy_metadata_count)
72 {
74 }
76 {
77 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
79 }
80 }
81
83 {
84 std::shared_lock<std::shared_mutex> lock(entity_mutex);
85 return std::any_cast<int>(metadata.at("data_variant_id"));
86 }
87
88 std::optional<int> FrogEntity::GetDataTongueTargetId() const
89 {
90 std::shared_lock<std::shared_mutex> lock(entity_mutex);
91 return std::any_cast<std::optional<int>>(metadata.at("data_tongue_target_id"));
92 }
93
94
95 void FrogEntity::SetDataVariantId(const int data_variant_id)
96 {
97 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
98 metadata["data_variant_id"] = data_variant_id;
99 }
100
101 void FrogEntity::SetDataTongueTargetId(const std::optional<int>& data_tongue_target_id)
102 {
103 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
104 metadata["data_tongue_target_id"] = data_tongue_target_id;
105 }
106
107
109 {
110 std::shared_lock<std::shared_mutex> lock(entity_mutex);
112 }
113
114
116 {
117 return 0.5;
118 }
119
121 {
122 return 0.5;
123 }
124
125}
126#endif
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
void SetDataVariantId(const int data_variant_id)
std::optional< int > GetDataTongueTargetId() const
static constexpr int metadata_count
void SetDataTongueTargetId(const std::optional< int > &data_tongue_target_id)
static std::string GetClassName()
static const std::array< std::string, metadata_count > metadata_names
virtual ProtocolCraft::Json::Value Serialize() const override
virtual double GetHeightImpl() const override
virtual EntityType GetType() const override
static constexpr int hierarchy_metadata_count
virtual std::string GetName() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static EntityType GetClassType()
virtual double GetWidthImpl() const override
int GetDataVariantId() const
double GetAttributeAttackDamageValue() const
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