Botcraft 1.21.4
Loading...
Searching...
No Matches
EntityAttribute.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iosfwd>
4#include <map>
5#include <optional>
6#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
7#include <string>
8#endif
9
10namespace Botcraft
11{
13 {
14 public:
15#if PROTOCOL_VERSION < 767 /* < 1.21 */
16 using ModifierKey = std::array<unsigned char, 16>;
17#else
18 using ModifierKey = std::string;
19#endif
20
21 enum class Type : char
22 {
23 Unknown = -1,
24 Armor,
27#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
29#endif
31#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
34#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
37#endif
40#endif
43#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
44 Gravity,
46#else
47 HorseJumpStrength,
48#endif
50 Luck,
51#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
53#endif
55#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
58#endif
60#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
62#endif
63#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
65 Scale,
66#endif
67#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
69#endif
71#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
73#endif
74#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
77#endif
78#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
80#endif
81#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
83#endif
85 };
86
87 struct Modifier
88 {
89 enum class Operation : char
90 {
91 Add = 0,
92 MultiplyBase = 1,
94 };
95
96 double amount = 0.0;
98 };
99
100 EntityAttribute(const Type type_, const double base_value_);
101 EntityAttribute() = delete;
102
103 void SetBaseValue(const double new_value);
104 void ClearModifiers();
105 void RemoveModifier(const ModifierKey& key);
106 void SetModifier(const ModifierKey& key, const Modifier& modifier);
107
108 Type GetType() const;
109 double GetBaseValue() const;
110 const std::map<ModifierKey, Modifier>& GetModifiers() const;
111 double GetValue() const;
112 std::optional<Modifier> GetModifier(const ModifierKey& key);
113
114#if PROTOCOL_VERSION < 766 /* < 1.20.4 */
115 static std::string TypeToString(const Type type);
116 static Type StringToType(const std::string& s);
117#endif
118
119 private:
120 void UpdateValue() const;
121
122 private:
125 mutable double current_value;
126 mutable bool up_to_date;
127 std::map<ModifierKey, Modifier> modifiers;
128
129 };
130 std::ostream& operator<<(std::ostream& os, const EntityAttribute::Type v);
131}
void RemoveModifier(const ModifierKey &key)
const std::map< ModifierKey, Modifier > & GetModifiers() const
std::optional< Modifier > GetModifier(const ModifierKey &key)
void SetBaseValue(const double new_value)
void SetModifier(const ModifierKey &key, const Modifier &modifier)
std::map< ModifierKey, Modifier > modifiers
std::ostream & operator<<(std::ostream &os, const EntityAttribute::Type v)