Botcraft 1.21.4
Loading...
Searching...
No Matches
GuardianEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, GuardianEntity::metadata_count> GuardianEntity::metadata_names{ {
8 "data_id_moving",
9 "data_id_attack_target",
10 } };
11
13 {
14 // Initialize all metadata with default values
15 SetDataIdMoving(false);
17
18 // Initialize all attributes with default values
21#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
23#endif
25 }
26
31
32
33 std::string GuardianEntity::GetName() const
34 {
35 return "guardian";
36 }
37
42
43
45 {
46 return "guardian";
47 }
48
53
54
56 {
58
59 output["metadata"]["data_id_moving"] = GetDataIdMoving();
60 output["metadata"]["data_id_attack_target"] = GetDataIdAttackTarget();
61
62 return output;
63 }
64
65
66 void GuardianEntity::SetMetadataValue(const int index, const std::any& value)
67 {
68 if (index < hierarchy_metadata_count)
69 {
71 }
73 {
74 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
76 }
77 }
78
80 {
81 std::shared_lock<std::shared_mutex> lock(entity_mutex);
82 return std::any_cast<bool>(metadata.at("data_id_moving"));
83 }
84
86 {
87 std::shared_lock<std::shared_mutex> lock(entity_mutex);
88 return std::any_cast<int>(metadata.at("data_id_attack_target"));
89 }
90
91
92 void GuardianEntity::SetDataIdMoving(const bool data_id_moving)
93 {
94 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
95 metadata["data_id_moving"] = data_id_moving;
96 }
97
98 void GuardianEntity::SetDataIdAttackTarget(const int data_id_attack_target)
99 {
100 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
101 metadata["data_id_attack_target"] = data_id_attack_target;
102 }
103
104
106 {
107 return 0.85;
108 }
109
111 {
112 return 0.85;
113 }
114
115}
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
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataIdMoving(const bool data_id_moving)
static const std::array< std::string, metadata_count > metadata_names
static std::string GetClassName()
virtual void SetMetadataValue(const int index, const std::any &value) override
static constexpr int hierarchy_metadata_count
static EntityType GetClassType()
virtual std::string GetName() const override
virtual double GetWidthImpl() const override
void SetDataIdAttackTarget(const int data_id_attack_target)
virtual double GetHeightImpl() const override
virtual EntityType GetType() const override
static constexpr int metadata_count
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