Botcraft 26.2
Loading...
Searching...
No Matches
AbstractCubeMobEntity.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, AbstractCubeMobEntity::metadata_count> AbstractCubeMobEntity::metadata_names{ {
10 "id_size",
11 } };
12
14 {
15 // Initialize all metadata with default values
16 SetIdSize(1);
17
18 // Initialize all attributes with default values
20 }
21
26
28 {
29 return true;
30 }
31
32
34 {
36
37 output["metadata"]["id_size"] = GetIdSize();
38
39 return output;
40 }
41
42
43 void AbstractCubeMobEntity::SetMetadataValue(const int index, const std::any& value)
44 {
45 if (index < hierarchy_metadata_count)
46 {
48 }
50 {
51 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
53 }
54 }
55
57 {
58 std::shared_lock<std::shared_mutex> lock(entity_mutex);
59 return GetIdSizeImpl();
60 }
61
62
63 void AbstractCubeMobEntity::SetIdSize(const int id_size)
64 {
65 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
66 metadata["id_size"] = id_size;
67 SizeChanged(id_size);
68#if USE_GUI
70#endif
71 }
72
73
75 {
76 return std::any_cast<bool>(metadata.at("id_size"));
77 }
78
79 void AbstractCubeMobEntity::SizeChanged(const int new_size)
80 {
82 if (it != attributes.end())
83 {
84 it->second.SetBaseValue(static_cast<double>(new_size) * new_size);
85 }
86 else
87 {
88 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MaxHealth << " for a CubeMob but it doesn't have this attribute");
89 }
90
92 if (it != attributes.end())
93 {
94 it->second.SetBaseValue(0.2 + 0.1 * new_size);
95 }
96 else
97 {
98 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MovementSpeed << " for a CubeMob but it doesn't have this attribute");
99 }
100 }
101}
102#endif
#define LOG_WARNING(osstream)
Definition Logger.hpp:44
static const std::array< std::string, metadata_count > metadata_names
virtual void SizeChanged(const int new_size)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual bool IsAbstractCubeMob() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
void OnSizeUpdated()
Definition Entity.cpp:2162
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
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45