Botcraft 26.3
Loading...
Searching...
No Matches
SalmonEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
3
4namespace Botcraft
5{
7 {
8 // Initialize all metadata with default values
10#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
11#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
12 SetDataType("medium");
13#else
14 SetDataType(1);
15#endif
16#endif
17 }
18
23
24
25 std::string SalmonEntity::GetName() const
26 {
27 return "salmon";
28 }
29
34
35
37 {
38 return "salmon";
39 }
40
45
46
47#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
49 {
51
52 output["metadata"]["data_type"] = GetDataType();
53
54 return output;
55 }
56
57
59 {
60 if (index < hierarchy_metadata_count)
61 {
63 }
64#if USE_GUI
65 else if (index == BOTCRAFT_ENTITY_METADATA_INDEX("data_type"))
66 {
68 }
69#endif
70 }
71
72#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
73 std::string SalmonEntity::GetDataType() const
74 {
75 std::shared_lock<std::shared_mutex> lock(entity_mutex);
76 return GetDataTypeImpl();
77 }
78
79 const std::string& SalmonEntity::GetDataTypeImpl() const
80 {
81 return GetMetadataImpl<const std::string&>(BOTCRAFT_ENTITY_METADATA_INDEX("data_type"));
82 }
83#else
85 {
86 std::shared_lock<std::shared_mutex> lock(entity_mutex);
87 return GetDataTypeImpl();
88 }
89
91 {
92 return GetMetadataImpl<int>(BOTCRAFT_ENTITY_METADATA_INDEX("data_type"));
93 }
94#endif
95
97 {
98#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
99 const std::string& type = GetDataTypeImpl();
100 if (type == "medium")
101 {
102 return 1.0;
103 }
104 else if (type == "small")
105 {
106 return 0.5;
107 }
108 else
109 {
110 return 1.5;
111 }
112#else
113 switch (GetDataTypeImpl())
114 {
115 case 0:
116 return 0.5;
117 case 1:
118 return 1.0;
119 case 2:
120 return 1.5;
121 default:
122 return 1.0;
123 }
124#endif
125 }
126
127#if PROTOCOL_VERSION < 769 /* < 1.21.4 */
128 void SalmonEntity::SetDataType(const std::string& data_type)
129#else
130 void SalmonEntity::SetDataType(const int data_type)
131#endif
132 {
133 SetMetadata(BOTCRAFT_ENTITY_METADATA_INDEX("data_type"), data_type);
134 }
135#endif
136
138 {
139#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
140 return 0.7;
141#else
142 return 0.7 * GetScaleImpl();
143#endif
144 }
145
147 {
148#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
149 return 0.4;
150#else
151 return 0.4 * GetScaleImpl();
152#endif
153 }
154
155}
156#endif
virtual ProtocolCraft::Json::Value Serialize() const override
void OnSizeUpdated()
Definition Entity.cpp:2179
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
double GetScaleImpl() const
virtual ProtocolCraft::Json::Value Serialize() const override
void OnMetadataChangedImpl(const int index) override
static constexpr int metadata_count
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
#define BOTCRAFT_ENTITY_METADATA_INDEX(name)
Definition Entity.hpp:347