Botcraft 1.21.4
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 "home_pos",
10 "has_egg",
11 "laying_egg",
12 "travel_pos",
13 "going_home",
14 "travelling",
15 } };
16
18 {
19 // Initialize all metadata with default values
20 SetHomePos(Position(0, 0, 0));
21 SetHasEgg(false);
22 SetLayingEgg(false);
23 SetTravelPos(Position(0, 0, 0));
24 SetGoingHome(false);
25 SetTravelling(false);
26
27 // Initialize all attributes with default values
30#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
32#endif
33 }
34
39
40
41 std::string TurtleEntity::GetName() const
42 {
43 return "turtle";
44 }
45
50
51
53 {
54 return "turtle";
55 }
56
61
62
64 {
66
67 output["metadata"]["home_pos"] = GetHomePos().Serialize();
68 output["metadata"]["has_egg"] = GetHasEgg();
69 output["metadata"]["laying_egg"] = GetLayingEgg();
70 output["metadata"]["travel_pos"] = GetTravelPos().Serialize();
71 output["metadata"]["going_home"] = GetGoingHome();
72 output["metadata"]["travelling"] = GetTravelling();
73
74 return output;
75 }
76
77
78 void TurtleEntity::SetMetadataValue(const int index, const std::any& value)
79 {
80 if (index < hierarchy_metadata_count)
81 {
83 }
85 {
86 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
88 }
89 }
90
92 {
93 std::shared_lock<std::shared_mutex> lock(entity_mutex);
94 return std::any_cast<Position>(metadata.at("home_pos"));
95 }
96
98 {
99 std::shared_lock<std::shared_mutex> lock(entity_mutex);
100 return std::any_cast<bool>(metadata.at("has_egg"));
101 }
102
104 {
105 std::shared_lock<std::shared_mutex> lock(entity_mutex);
106 return std::any_cast<bool>(metadata.at("laying_egg"));
107 }
108
110 {
111 std::shared_lock<std::shared_mutex> lock(entity_mutex);
112 return std::any_cast<Position>(metadata.at("travel_pos"));
113 }
114
116 {
117 std::shared_lock<std::shared_mutex> lock(entity_mutex);
118 return std::any_cast<bool>(metadata.at("going_home"));
119 }
120
122 {
123 std::shared_lock<std::shared_mutex> lock(entity_mutex);
124 return std::any_cast<bool>(metadata.at("travelling"));
125 }
126
127
128 void TurtleEntity::SetHomePos(const Position& home_pos)
129 {
130 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
131 metadata["home_pos"] = home_pos;
132 }
133
134 void TurtleEntity::SetHasEgg(const bool has_egg)
135 {
136 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
137 metadata["has_egg"] = has_egg;
138 }
139
140 void TurtleEntity::SetLayingEgg(const bool laying_egg)
141 {
142 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
143 metadata["laying_egg"] = laying_egg;
144 }
145
146 void TurtleEntity::SetTravelPos(const Position& travel_pos)
147 {
148 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
149 metadata["travel_pos"] = travel_pos;
150 }
151
152 void TurtleEntity::SetGoingHome(const bool going_home)
153 {
154 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
155 metadata["going_home"] = going_home;
156 }
157
158 void TurtleEntity::SetTravelling(const bool travelling)
159 {
160 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
161 metadata["travelling"] = travelling;
162 }
163
164
166 {
167 return 1.2;
168 }
169
171 {
172 return 0.4;
173 }
174
175}
176#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
std::map< EntityAttribute::Type, EntityAttribute > attributes
static EntityType GetClassType()
void SetTravelPos(const Position &travel_pos)
Position GetTravelPos() const
void SetGoingHome(const bool going_home)
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()
void SetTravelling(const bool travelling)
static constexpr int hierarchy_metadata_count
void SetHomePos(const Position &home_pos)
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
Position GetHomePos() const
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
ProtocolCraft::Json::Value Serialize() const
Definition Vector3.hpp:267