Botcraft 26.3
Loading...
Searching...
No Matches
SlimeEntity.cpp
Go to the documentation of this file.
3
4namespace Botcraft
5{
7 {
8 // Initialize all metadata with default values
10 // As Slime don't inherit from MonsterEntity, AttackDamage is not initialized in parent constructor
11 // It is overwritten when size is set, but it needs to be initialized before
13
14#if PROTOCOL_VERSION < 776 /* < 26.2 */
15 SetIdSize(1);
16#endif
17 }
18
23
24
25 std::string SlimeEntity::GetName() const
26 {
27 return "slime";
28 }
29
34
35
37 {
38 return "slime";
39 }
40
45
46#if PROTOCOL_VERSION < 776 /* < 26.2 */
48 {
50
51 output["metadata"]["id_size"] = GetIdSize();
52
53 return output;
54 }
55
56
57 void SlimeEntity::OnMetadataChangedImpl(const int index)
58 {
59 if (index < hierarchy_metadata_count)
60 {
62 }
63 else if (index == BOTCRAFT_ENTITY_METADATA_INDEX("id_size"))
64 {
65 SizeChanged(GetMetadataImpl<int>(index));
66#if USE_GUI
68#endif
69 }
70 }
71
72 int SlimeEntity::GetIdSize() const
73 {
74 std::shared_lock<std::shared_mutex> lock(entity_mutex);
75 return GetIdSizeImpl();
76 }
77
78
79 void SlimeEntity::SetIdSize(const int id_size)
80 {
82 }
83
85 {
86 return GetMetadataImpl<int>(BOTCRAFT_ENTITY_METADATA_INDEX("id_size"));
87 }
88
89 void SlimeEntity::SizeChanged(const int new_size)
90 {
92 if (it != attributes.end())
93 {
94 it->second.SetBaseValue(static_cast<double>(new_size) * new_size);
95 }
96 else
97 {
98 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MaxHealth << " for a " << GetName() << " but it doesn't have this attribute");
99 }
100
102 if (it != attributes.end())
103 {
104 it->second.SetBaseValue(0.2 + 0.1 * new_size);
105 }
106 else
107 {
108 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::MovementSpeed << " for a " << GetName() << " but it doesn't have this attribute");
109 }
110
112 if (it != attributes.end())
113 {
114 it->second.SetBaseValue(static_cast<double>(new_size));
115 }
116 else
117 {
118 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::AttackDamage << " for a slime but it doesn't have this attribute");
119 }
120 }
121#else
122 void SlimeEntity::SizeChanged(const int new_size)
123 {
126 if (it != attributes.end())
127 {
128 it->second.SetBaseValue(static_cast<double>(new_size));
129 }
130 else
131 {
132 LOG_WARNING("Trying to set attribute base value for " << EntityAttribute::Type::AttackDamage << " for a slime but it doesn't have this attribute");
133 }
134 }
135#endif
136
138 {
139#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
140 return 0.255 * 2.04 * GetIdSizeImpl();
141#else
142 return 0.52 * GetIdSizeImpl();
143#endif
144 }
145
147 {
148#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
149 return 0.255 * 2.04 * GetIdSizeImpl();
150#else
151 return 0.52 * GetIdSizeImpl();
152#endif
153 }
154
155}
#define LOG_WARNING(osstream)
Definition Logger.hpp:44
virtual void SizeChanged(const int new_size)
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
virtual ProtocolCraft::Json::Value Serialize() const override
Definition MobEntity.cpp:29
virtual double GetHeightImpl() const override
static constexpr int hierarchy_metadata_count
static std::string GetClassName()
virtual void SizeChanged(const int new_size) override
static EntityType GetClassType()
static constexpr int metadata_count
virtual std::string GetName() const override
virtual EntityType GetType() const override
virtual double GetWidthImpl() const override
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