Botcraft 1.21.5
Loading...
Searching...
No Matches
TurtleEntity.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, TurtleEntity::metadata_count> TurtleEntity::metadata_names{ {
9#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
10 "home_pos",
11#endif
12 "has_egg",
13 "laying_egg",
14#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
15 "travel_pos",
16 "going_home",
17 "travelling",
18#endif
19 } };
20
22 {
23 // Initialize all metadata with default values
24#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
25 SetHomePos(Position(0, 0, 0));
26#endif
27 SetHasEgg(false);
28 SetLayingEgg(false);
29#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
30 SetTravelPos(Position(0, 0, 0));
31 SetGoingHome(false);
32 SetTravelling(false);
33#endif
34
35 // Initialize all attributes with default values
38#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
40#endif
41 }
42
47
48
49 std::string TurtleEntity::GetName() const
50 {
51 return "turtle";
52 }
53
58
59
61 {
62 return "turtle";
63 }
64
69
70
72 {
74
75#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
76 output["metadata"]["home_pos"] = GetHomePos().Serialize();
77#endif
78 output["metadata"]["has_egg"] = GetHasEgg();
79 output["metadata"]["laying_egg"] = GetLayingEgg();
80#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
81 output["metadata"]["travel_pos"] = GetTravelPos().Serialize();
82 output["metadata"]["going_home"] = GetGoingHome();
83 output["metadata"]["travelling"] = GetTravelling();
84#endif
85
86 return output;
87 }
88
89
90 void TurtleEntity::SetMetadataValue(const int index, const std::any& value)
91 {
92 if (index < hierarchy_metadata_count)
93 {
95 }
97 {
98 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
100 }
101 }
102
103#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
104 Position TurtleEntity::GetHomePos() const
105 {
106 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 return std::any_cast<Position>(metadata.at("home_pos"));
108 }
109#endif
110
112 {
113 std::shared_lock<std::shared_mutex> lock(entity_mutex);
114 return std::any_cast<bool>(metadata.at("has_egg"));
115 }
116
118 {
119 std::shared_lock<std::shared_mutex> lock(entity_mutex);
120 return std::any_cast<bool>(metadata.at("laying_egg"));
121 }
122
123#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
124 Position TurtleEntity::GetTravelPos() const
125 {
126 std::shared_lock<std::shared_mutex> lock(entity_mutex);
127 return std::any_cast<Position>(metadata.at("travel_pos"));
128 }
129
130 bool TurtleEntity::GetGoingHome() const
131 {
132 std::shared_lock<std::shared_mutex> lock(entity_mutex);
133 return std::any_cast<bool>(metadata.at("going_home"));
134 }
135
136 bool TurtleEntity::GetTravelling() const
137 {
138 std::shared_lock<std::shared_mutex> lock(entity_mutex);
139 return std::any_cast<bool>(metadata.at("travelling"));
140 }
141#endif
142
143
144#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
145 void TurtleEntity::SetHomePos(const Position& home_pos)
146 {
147 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
148 metadata["home_pos"] = home_pos;
149 }
150#endif
151
152 void TurtleEntity::SetHasEgg(const bool has_egg)
153 {
154 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
155 metadata["has_egg"] = has_egg;
156 }
157
158 void TurtleEntity::SetLayingEgg(const bool laying_egg)
159 {
160 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
161 metadata["laying_egg"] = laying_egg;
162 }
163
164#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
165 void TurtleEntity::SetTravelPos(const Position& travel_pos)
166 {
167 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
168 metadata["travel_pos"] = travel_pos;
169 }
170
171 void TurtleEntity::SetGoingHome(const bool going_home)
172 {
173 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
174 metadata["going_home"] = going_home;
175 }
176
177 void TurtleEntity::SetTravelling(const bool travelling)
178 {
179 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
180 metadata["travelling"] = travelling;
181 }
182#endif
183
184
186 {
187 return 1.2;
188 }
189
191 {
192 return 0.4;
193 }
194
195}
196#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:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
std::map< EntityAttribute::Type, EntityAttribute > attributes
static EntityType GetClassType()
static constexpr int metadata_count
virtual double GetHeightImpl() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static std::string GetClassName()
static constexpr int hierarchy_metadata_count
virtual ProtocolCraft::Json::Value Serialize() const override
void SetLayingEgg(const bool laying_egg)
virtual double GetWidthImpl() const override
virtual EntityType GetType() const override
static const std::array< std::string, metadata_count > metadata_names
void SetHasEgg(const bool has_egg)
virtual std::string GetName() const override
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