Botcraft 1.21.4
Loading...
Searching...
No Matches
CreakingEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, CreakingEntity::metadata_count> CreakingEntity::metadata_names{ {
9 "can_move",
10 "is_active",
11#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
12 "is_tearing_down",
13 "home_pose",
14#endif
15 } };
16
40
45
46
47 std::string CreakingEntity::GetName() const
48 {
49 return "creaking";
50 }
51
56
57
59 {
60 return "creaking";
61 }
62
67
68
70 {
72
73 output["metadata"]["can_move"] = GetCanMove();
74 output["metadata"]["is_active"] = GetIsActive();
75#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
76 output["metadata"]["is_tearing_down"] = GetIsTearingDown();
77 output["metadata"]["is_tearing_down"] = GetHomePos() ? GetHomePos().value().Serialize() : ProtocolCraft::Json::Value(nullptr);
78#endif
79
80
81 return output;
82 }
83
84
85 void CreakingEntity::SetMetadataValue(const int index, const std::any& value)
86 {
87 if (index < hierarchy_metadata_count)
88 {
90 }
92 {
94 }
95 }
96
98 {
99 std::shared_lock<std::shared_mutex> lock(entity_mutex);
100 return std::any_cast<bool>(metadata.at("can_move"));
101 }
102
104 {
105 std::shared_lock<std::shared_mutex> lock(entity_mutex);
106 return std::any_cast<bool>(metadata.at("is_active"));
107 }
108
109#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
111 {
112 std::shared_lock<std::shared_mutex> lock(entity_mutex);
113 return std::any_cast<bool>(metadata.at("is_tearing_down"));
114 }
115
116 const std::optional<Position>& CreakingEntity::GetHomePos() const
117 {
118 std::shared_lock<std::shared_mutex> lock(entity_mutex);
119 return std::any_cast<const std::optional<Position>&>(metadata.at("home_pos"));
120 }
121#endif
122
123
124 void CreakingEntity::SetCanMove(const bool can_move)
125 {
126 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
127 metadata["can_move"] = can_move;
128 }
129
130 void CreakingEntity::SetIsActive(const bool is_active)
131 {
132 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
133 metadata["is_active"] = is_active;
134 }
135
136#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
137 void CreakingEntity::SetIsTearingDown(const bool is_tearing_down)
138 {
139 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
140 metadata["is_tearing_down"] = is_tearing_down;
141 }
142
143 void CreakingEntity::SetHomePos(const std::optional<Position>& home_pos)
144 {
145 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
146 metadata["home_pos"] = home_pos;
147 }
148#endif
149
150
152 {
153 return 0.9;
154 }
155
157 {
158 return 2.7;
159 }
160
161}
162#endif
virtual EntityType GetType() const override
static std::string GetClassName()
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual double GetWidthImpl() const override
virtual std::string GetName() const override
static constexpr int hierarchy_metadata_count
void SetHomePos(const std::optional< Position > &home_pos)
static EntityType GetClassType()
const std::optional< Position > & GetHomePos() const
virtual double GetHeightImpl() const override
virtual ProtocolCraft::Json::Value Serialize() const override
static constexpr int metadata_count
void SetCanMove(const bool can_move)
static const std::array< std::string, metadata_count > metadata_names
void SetIsTearingDown(const bool is_tearing_down)
void SetIsActive(const bool is_active)
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45