Botcraft 1.21.7
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 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 */
36#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
38#endif
40#endif
43#endif
46#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
47 Gravity,
49#else
50 HorseJumpStrength,
51#endif
53 Luck,
54#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
56#endif
58#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
61#endif
63#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
65#endif
66#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
68 Scale,
69#endif
70#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
72#endif
74#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
76#endif
77#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
80#endif
81#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
83#endif
84#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
86#endif
87#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
90#endif
92 };
93
94 struct Modifier
95 {
96 enum class Operation : char
97 {
98 Add = 0,
99 MultiplyBase = 1,
100 MultiplyTotal = 2
101 };
102
103 double amount = 0.0;
105 };
106
107 EntityAttribute(const Type type_, const double base_value_);
108 EntityAttribute() = delete;
109
110 void SetBaseValue(const double new_value);
111 void ClearModifiers();
112 void RemoveModifier(const ModifierKey& key);
113 void SetModifier(const ModifierKey& key, const Modifier& modifier);
114
115 Type GetType() const;
116 double GetBaseValue() const;
117 const std::map<ModifierKey, Modifier>& GetModifiers() const;
118 double GetValue() const;
119 std::optional<Modifier> GetModifier(const ModifierKey& key);
120
121#if PROTOCOL_VERSION < 766 /* < 1.20.4 */
122 static std::string TypeToString(const Type type);
123 static Type StringToType(const std::string& s);
124#endif
125
126 private:
127 void UpdateValue() const;
128
129 private:
132 mutable double current_value;
133 mutable bool up_to_date;
134 std::map<ModifierKey, Modifier> modifiers;
135
136 };
137 std::ostream& operator<<(std::ostream& os, const EntityAttribute::Type v);
138}
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)