Botcraft 26.3
Loading...
Searching...
No Matches
AbstractCubeMobEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
4
5namespace Botcraft
6{
8 {
9 // Initialize all metadata with default values
11 SetIdSize(1);
12
13 // Initialize all attributes with default values
15 }
16
21
23 {
24 return true;
25 }
26
27
29 {
31
32 output["metadata"]["id_size"] = GetIdSize();
33
34 return output;
35 }
36
37
39 {
40 if (index < hierarchy_metadata_count)
41 {
43 }
44 else if (index == BOTCRAFT_ENTITY_METADATA_INDEX("id_size"))
45 {
46 SizeChanged(GetMetadataImpl<int>(index));
47#if USE_GUI
49#endif
50 }
51 }
52
54 {
55 std::shared_lock<std::shared_mutex> lock(entity_mutex);
56 return GetIdSizeImpl();
57 }
58
59
60 void AbstractCubeMobEntity::SetIdSize(const int id_size)
61 {
63 }
64
65
67 {
68 return GetMetadataImpl<int>(BOTCRAFT_ENTITY_METADATA_INDEX("id_size"));
69 }
70
71 void AbstractCubeMobEntity::SizeChanged(const int new_size)
72 {
74 if (it != attributes.end())
75 {
76 it->second.SetBaseValue(static_cast<double>(new_size) * new_size);
77 }
78 else
79 {
80 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MaxHealth << " for a CubeMob but it doesn't have this attribute");
81 }
82
84 if (it != attributes.end())
85 {
86 it->second.SetBaseValue(0.2 + 0.1 * new_size);
87 }
88 else
89 {
90 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MovementSpeed << " for a CubeMob but it doesn't have this attribute");
91 }
92 }
93}
94#endif
#define LOG_WARNING(osstream)
Definition Logger.hpp:44
virtual void SizeChanged(const int new_size)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual bool IsAbstractCubeMob() const override
void OnMetadataChangedImpl(const int index) override
virtual ProtocolCraft::Json::Value Serialize() const override
void OnSizeUpdated()
Definition Entity.cpp:2179
void SetMetadata(const int index, const std::any &value)
Definition Entity.cpp:366
std::shared_mutex entity_mutex
Definition Entity.hpp:320
std::vector< std::any > metadata
Definition Entity.hpp:335
virtual void OnMetadataChangedImpl(const int index)
Definition Entity.cpp:372
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
#define BOTCRAFT_ENTITY_METADATA_INDEX(name)
Definition Entity.hpp:347