Botcraft 1.21.7
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 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 }
96 }
97
99 {
100 std::shared_lock<std::shared_mutex> lock(entity_mutex);
101 return std::any_cast<bool>(metadata.at("can_move"));
102 }
103
105 {
106 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 return std::any_cast<bool>(metadata.at("is_active"));
108 }
109
110#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
112 {
113 std::shared_lock<std::shared_mutex> lock(entity_mutex);
114 return std::any_cast<bool>(metadata.at("is_tearing_down"));
115 }
116
117 const std::optional<Position>& CreakingEntity::GetHomePos() const
118 {
119 std::shared_lock<std::shared_mutex> lock(entity_mutex);
120 return std::any_cast<const std::optional<Position>&>(metadata.at("home_pos"));
121 }
122#endif
123
124
125 void CreakingEntity::SetCanMove(const bool can_move)
126 {
127 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
128 metadata["can_move"] = can_move;
129 }
130
131 void CreakingEntity::SetIsActive(const bool is_active)
132 {
133 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
134 metadata["is_active"] = is_active;
135 }
136
137#if PROTOCOL_VERSION > 768 /* > 1.21.3 */
138 void CreakingEntity::SetIsTearingDown(const bool is_tearing_down)
139 {
140 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
141 metadata["is_tearing_down"] = is_tearing_down;
142 }
143
144 void CreakingEntity::SetHomePos(const std::optional<Position>& home_pos)
145 {
146 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
147 metadata["home_pos"] = home_pos;
148 }
149#endif
150
151
153 {
154 return 0.9;
155 }
156
158 {
159 return 2.7;
160 }
161
162}
163#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:681
std::shared_mutex entity_mutex
Definition Entity.hpp:261
std::map< std::string, std::any > metadata
Definition Entity.hpp:276
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