Botcraft 1.21.4
Loading...
Searching...
No Matches
SalmonEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
9 const std::array<std::string, SalmonEntity::metadata_count> SalmonEntity::metadata_names{ {
10 "data_type",
11 } };
12#endif
13
15 {
16 // Initialize all metadata with default values
17#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
18#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
19 SetDataType("medium");
20#else
21 SetDataType(1);
22#endif
23#endif
24 }
25
30
31
32 std::string SalmonEntity::GetName() const
33 {
34 return "salmon";
35 }
36
41
42
44 {
45 return "salmon";
46 }
47
52
53
54#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
56 {
58
59 output["metadata"]["data_type"] = GetDataType();
60
61 return output;
62 }
63
64
65 void SalmonEntity::SetMetadataValue(const int index, const std::any& value)
66 {
67 if (index < hierarchy_metadata_count)
68 {
70 }
72 {
73 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
75 }
76 }
77
78#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
79 const std::string& SalmonEntity::GetDataType() const
80 {
81 std::shared_lock<std::shared_mutex> lock(entity_mutex);
82 return GetDataTypeImpl();
83 }
84
85 const std::string& SalmonEntity::GetDataTypeImpl() const
86 {
87 return std::any_cast<const std::string&>(metadata.at("data_type"));
88 }
89#else
91 {
92 std::shared_lock<std::shared_mutex> lock(entity_mutex);
93 return GetDataTypeImpl();
94 }
95
97 {
98 return std::any_cast<int>(metadata.at("data_type"));
99 }
100#endif
101
103 {
104#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
105 const std::string& type = GetDataTypeImpl();
106 if (type == "medium")
107 {
108 return 1.0;
109 }
110 else if (type == "small")
111 {
112 return 0.5;
113 }
114 else
115 {
116 return 1.5;
117 }
118#else
119 switch (GetDataTypeImpl())
120 {
121 case 0:
122 return 0.5;
123 case 1:
124 return 1.0;
125 case 2:
126 return 1.5;
127 default:
128 return 1.0;
129 }
130#endif
131 }
132
133#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
134 void SalmonEntity::SetDataType(const std::string& data_type)
135#else
136 void SalmonEntity::SetDataType(const int data_type)
137#endif
138 {
139 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
140 metadata["data_type"] = data_type;
141#if USE_GUI
142 OnSizeUpdated();
143#endif
144 }
145#endif
146
148 {
149#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
150 return 0.7;
151#else
152 return 0.7 * GetScaleImpl();
153#endif
154 }
155
157 {
158#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
159 return 0.4;
160#else
161 return 0.4 * GetScaleImpl();
162#endif
163 }
164
165}
166#endif
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
double GetScaleImpl() const
virtual ProtocolCraft::Json::Value Serialize() const override
static const std::array< std::string, metadata_count > metadata_names
static constexpr int metadata_count
virtual void SetMetadataValue(const int index, const std::any &value) override
static constexpr int hierarchy_metadata_count
static EntityType GetClassType()
virtual double GetHeightImpl() const override
virtual double GetWidthImpl() const override
virtual std::string GetName() const override
static std::string GetClassName()
void SetDataType(const int data_type)
virtual EntityType GetType() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45