Botcraft 1.21.5
Loading...
Searching...
No Matches
DolphinEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, DolphinEntity::metadata_count> DolphinEntity::metadata_names{ {
9#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
10 "treasure_pos",
11#endif
12 "got_fish",
13 "moistness_level",
14 } };
15
17 {
18 // Initialize all metadata with default values
19#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
20 SetTreasurePos(Position(0, 0, 0));
21#endif
22 SetGotFish(false);
24
25 // Initialize all attributes with default values
29 }
30
35
36
37 std::string DolphinEntity::GetName() const
38 {
39 return "dolphin";
40 }
41
46
47
49 {
50 return "dolphin";
51 }
52
57
58
60 {
61#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
63#else
65#endif
66
67#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
68 output["metadata"]["treasure_pos"] = GetTreasurePos().Serialize();
69#endif
70 output["metadata"]["got_fish"] = GetGotFish();
71 output["metadata"]["moistness_level"] = GetMoistnessLevel();
72
73 output["attributes"]["attack_damage"] = GetAttributeAttackDamageValue();
74
75 return output;
76 }
77
78
79 void DolphinEntity::SetMetadataValue(const int index, const std::any& value)
80 {
81 if (index < hierarchy_metadata_count)
82 {
83#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
85#else
87#endif
88 }
90 {
91 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
93 }
94 }
95
96#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
97 Position DolphinEntity::GetTreasurePos() const
98 {
99 std::shared_lock<std::shared_mutex> lock(entity_mutex);
100 return std::any_cast<Position>(metadata.at("treasure_pos"));
101 }
102#endif
103
105 {
106 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 return std::any_cast<bool>(metadata.at("got_fish"));
108 }
109
111 {
112 std::shared_lock<std::shared_mutex> lock(entity_mutex);
113 return std::any_cast<int>(metadata.at("moistness_level"));
114 }
115
116
117#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
118 void DolphinEntity::SetTreasurePos(const Position& treasure_pos)
119 {
120 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
121 metadata["treasure_pos"] = treasure_pos;
122 }
123#endif
124
125 void DolphinEntity::SetGotFish(const bool got_fish)
126 {
127 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
128 metadata["got_fish"] = got_fish;
129 }
130
131 void DolphinEntity::SetMoistnessLevel(const int moistness_level)
132 {
133 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
134 metadata["moistness_level"] = moistness_level;
135 }
136
137
139 {
140 std::shared_lock<std::shared_mutex> lock(entity_mutex);
142 }
143
144
146 {
147 return 0.9;
148 }
149
151 {
152 return 0.6;
153 }
154
155}
156#endif
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static const std::array< std::string, metadata_count > metadata_names
virtual EntityType GetType() const override
double GetAttributeAttackDamageValue() const
virtual std::string GetName() const override
static constexpr int metadata_count
virtual double GetWidthImpl() const override
static EntityType GetClassType()
virtual double GetHeightImpl() const override
virtual ProtocolCraft::Json::Value Serialize() const override
static constexpr int hierarchy_metadata_count
void SetMoistnessLevel(const int moistness_level)
void SetGotFish(const bool got_fish)
virtual void SetMetadataValue(const int index, const std::any &value) override
static std::string GetClassName()
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1151
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:678
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
Vector3< int > Position
Definition Vector3.hpp:282