Botcraft 1.21.4
Loading...
Searching...
No Matches
EndCrystalEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, EndCrystalEntity::metadata_count> EndCrystalEntity::metadata_names{ {
8 "data_beam_target",
9 "data_show_bottom",
10 } };
11
13 {
14 // Initialize all metadata with default values
15 SetDataBeamTarget(std::optional<Position>());
17 }
18
23
24
25 std::string EndCrystalEntity::GetName() const
26 {
27 return "end_crystal";
28 }
29
34
35
37 {
38 return "end_crystal";
39 }
40
45
46
48 {
50
51 output["metadata"]["data_beam_target"] = GetDataBeamTarget() ? GetDataBeamTarget().value().Serialize() : ProtocolCraft::Json::Value();
52 output["metadata"]["data_show_bottom"] = GetDataShowBottom();
53
54 return output;
55 }
56
57
58 void EndCrystalEntity::SetMetadataValue(const int index, const std::any& value)
59 {
60 if (index < hierarchy_metadata_count)
61 {
62 Entity::SetMetadataValue(index, value);
63 }
65 {
66 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
68 }
69 }
70
71 std::optional<Position> EndCrystalEntity::GetDataBeamTarget() const
72 {
73 std::shared_lock<std::shared_mutex> lock(entity_mutex);
74 return std::any_cast<std::optional<Position>>(metadata.at("data_beam_target"));
75 }
76
78 {
79 std::shared_lock<std::shared_mutex> lock(entity_mutex);
80 return std::any_cast<bool>(metadata.at("data_show_bottom"));
81 }
82
83
84 void EndCrystalEntity::SetDataBeamTarget(const std::optional<Position>& data_beam_target)
85 {
86 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
87 metadata["data_beam_target"] = data_beam_target;
88 }
89
90 void EndCrystalEntity::SetDataShowBottom(const bool data_show_bottom)
91 {
92 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
93 metadata["data_show_bottom"] = data_show_bottom;
94 }
95
96
98 {
99 return 2.0;
100 }
101
103 {
104 return 2.0;
105 }
106
107}
static std::string GetClassName()
static constexpr int hierarchy_metadata_count
virtual double GetWidthImpl() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
virtual double GetHeightImpl() const override
static EntityType GetClassType()
virtual ProtocolCraft::Json::Value Serialize() const override
static const std::array< std::string, metadata_count > metadata_names
virtual EntityType GetType() const override
std::optional< Position > GetDataBeamTarget() const
static constexpr int metadata_count
void SetDataShowBottom(const bool data_show_bottom)
void SetDataBeamTarget(const std::optional< Position > &data_beam_target)
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1095
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45