Botcraft 26.2
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 : int
22 {
23 Unknown = -1,
24#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
26#endif
27 Armor,
30#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
32#endif
34#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
36#endif
37#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
40#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
42#endif
43#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
45#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
47#endif
49#endif
52#endif
55#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
57#endif
58#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
59 Gravity,
61#else
62 HorseJumpStrength,
63#endif
65 Luck,
66#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
68#endif
70#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
73#endif
75#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
77#endif
78#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
80#endif
81#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
83 Scale,
84#endif
85#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
87#endif
89#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
91#endif
92#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
95#endif
96#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
98#endif
99#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
101#endif
102#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
105#endif
107 };
108
109 struct Modifier
110 {
111 enum class Operation : char
112 {
113 Add = 0,
114 MultiplyBase = 1,
115 MultiplyTotal = 2
116 };
117
118 double amount = 0.0;
120 };
121
122 EntityAttribute(const Type type_, const double base_value_);
123 EntityAttribute() = delete;
124
125 void SetBaseValue(const double new_value);
126 void ClearModifiers();
127 void RemoveModifier(const ModifierKey& key);
128 void SetModifier(const ModifierKey& key, const Modifier& modifier);
129
130 Type GetType() const;
131 double GetBaseValue() const;
132 const std::map<ModifierKey, Modifier>& GetModifiers() const;
133 double GetValue() const;
134 std::optional<Modifier> GetModifier(const ModifierKey& key);
135
136#if PROTOCOL_VERSION < 766 /* < 1.20.4 */
137 static std::string TypeToString(const Type type);
138 static Type StringToType(const std::string& s);
139#endif
140
141 private:
142 void UpdateValue() const;
143
144 private:
147 mutable double current_value;
148 mutable bool up_to_date;
149 std::map<ModifierKey, Modifier> modifiers;
150
151 };
152 std::ostream& operator<<(std::ostream& os, const EntityAttribute::Type v);
153}
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)