Botcraft 26.2
Loading...
Searching...
No Matches
SulfurCubeEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
4
5#include <mutex>
6
7namespace Botcraft
8{
9 const std::array<std::string, SulfurCubeEntity::metadata_count> SulfurCubeEntity::metadata_names{ {
10 "max_fuse",
11 "from_bucket",
12 } };
13
15 {
16 // Initialize all metadata with default values
17 SetMaxFuse(-1);
18 SetFromBucket(false);
19
20 // Initialize all attributes with default values
22 }
23
28
29
30 std::string SulfurCubeEntity::GetName() const
31 {
32 return "sulfur_cube";
33 }
34
39
40
42 {
43 return "sulfur_cube";
44 }
45
50
51
53 {
55
56 output["metadata"]["max_fuse"] = GetMaxFuse();
57 output["metadata"]["from_bucket"] = GetFromBucket();
58
59 output["attributes"]["tempt_range"] = GetAttributeTemptRangeValue();
60
61 return output;
62 }
63
64
65 void SulfurCubeEntity::SetMetadataValue(const int index, const std::any& value)
66 {
67 if (index < hierarchy_metadata_count)
68 {
70 }
72 {
73 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
75 }
76 }
77
79 {
80 std::shared_lock<std::shared_mutex> lock(entity_mutex);
81 return std::any_cast<int>(metadata.at("max_fuse"));
82 }
83
85 {
86 std::shared_lock<std::shared_mutex> lock(entity_mutex);
87 return std::any_cast<bool>(metadata.at("from_bucket"));
88 }
89
90
91 void SulfurCubeEntity::SetMaxFuse(const int max_fuse)
92 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
94 metadata["max_fuse"] = max_fuse;
95 }
96
97 void SulfurCubeEntity::SetFromBucket(const bool from_bucket)
98 {
99 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
100 metadata["from_bucket"] = from_bucket;
101 }
102
103
105 {
106 std::shared_lock<std::shared_mutex> lock(entity_mutex);
107 return attributes.at(EntityAttribute::Type::TemptRange).GetValue();
108 }
109
110
111 void SulfurCubeEntity::SizeChanged(const int new_size)
112 {
115 if (it != attributes.end())
116 {
117 it->second.SetBaseValue(static_cast<double>(new_size) * 4.0);
118 }
119 else
120 {
121 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MaxHealth << " for a sulfur cube but it doesn't have this attribute");
122 }
123 }
124
126 {
127 return 0.49;
128 }
129
131 {
132 return 0.49;
133 }
134
135}
136#endif
#define LOG_WARNING(osstream)
Definition Logger.hpp:44
virtual void SizeChanged(const int new_size)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
std::shared_mutex entity_mutex
Definition Entity.hpp:270
std::map< std::string, std::any > metadata
Definition Entity.hpp:285
std::map< EntityAttribute::Type, EntityAttribute > attributes
virtual double GetHeightImpl() const override
double GetAttributeTemptRangeValue() const
virtual EntityType GetType() const override
virtual double GetWidthImpl() const override
virtual ProtocolCraft::Json::Value Serialize() const override
void SetMaxFuse(const int max_fuse)
static EntityType GetClassType()
static constexpr int hierarchy_metadata_count
void SetFromBucket(const bool from_bucket)
static constexpr int metadata_count
virtual void SizeChanged(const int new_size) override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
static const std::array< std::string, metadata_count > metadata_names
static std::string GetClassName()
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45