Botcraft 1.21.4
Loading...
Searching...
No Matches
AbstractMinecartEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, AbstractMinecartEntity::metadata_count> AbstractMinecartEntity::metadata_names{ {
8#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
9 "data_id_hurt",
10 "data_id_hurtdir",
11 "data_id_damage",
12#endif
13 "data_id_display_block",
14 "data_id_display_offset",
15 "data_id_custom_display",
16 } };
17
19 {
20 // Initialize all metadata with default values
21#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
24 SetDataIdDamage(0.0f);
25#endif
29 }
30
35
37 {
38 return true;
39 }
40
41
43 {
44#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
46#else
48#endif
49
50#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
51 output["metadata"]["data_id_hurt"] = GetDataIdHurt();
52 output["metadata"]["data_id_hurtdir"] = GetDataIdHurtdir();
53 output["metadata"]["data_id_damage"] = GetDataIdDamage();
54#endif
55 output["metadata"]["data_id_display_block"] = GetDataIdDisplayBlock();
56 output["metadata"]["data_id_display_offset"] = GetDataIdDisplayOffset();
57 output["metadata"]["data_id_custom_display"] = GetDataIdCustomDisplay();
58
59 return output;
60 }
61
62
63 void AbstractMinecartEntity::SetMetadataValue(const int index, const std::any& value)
64 {
65 if (index < hierarchy_metadata_count)
66 {
67#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
68 Entity::SetMetadataValue(index, value);
69#else
71#endif
72 }
74 {
75 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
77 }
78 }
79
80#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
82 {
83 std::shared_lock<std::shared_mutex> lock(entity_mutex);
84 return std::any_cast<int>(metadata.at("data_id_hurt"));
85 }
86
88 {
89 std::shared_lock<std::shared_mutex> lock(entity_mutex);
90 return std::any_cast<int>(metadata.at("data_id_hurtdir"));
91 }
92
94 {
95 std::shared_lock<std::shared_mutex> lock(entity_mutex);
96 return std::any_cast<float>(metadata.at("data_id_damage"));
97 }
98#endif
99
101 {
102 std::shared_lock<std::shared_mutex> lock(entity_mutex);
103 return std::any_cast<int>(metadata.at("data_id_display_block"));
104 }
105
107 {
108 std::shared_lock<std::shared_mutex> lock(entity_mutex);
109 return std::any_cast<int>(metadata.at("data_id_display_offset"));
110 }
111
113 {
114 std::shared_lock<std::shared_mutex> lock(entity_mutex);
115 return std::any_cast<bool>(metadata.at("data_id_custom_display"));
116 }
117
118
119#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
120 void AbstractMinecartEntity::SetDataIdHurt(const int data_id_hurt)
121 {
122 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
123 metadata["data_id_hurt"] = data_id_hurt;
124 }
125
126 void AbstractMinecartEntity::SetDataIdHurtdir(const int data_id_hurtdir)
127 {
128 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
129 metadata["data_id_hurtdir"] = data_id_hurtdir;
130 }
131
132 void AbstractMinecartEntity::SetDataIdDamage(const float data_id_damage)
133 {
134 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
135 metadata["data_id_damage"] = data_id_damage;
136 }
137#endif
138
139 void AbstractMinecartEntity::SetDataIdDisplayBlock(const int data_id_display_block)
140 {
141 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
142 metadata["data_id_display_block"] = data_id_display_block;
143 }
144
145 void AbstractMinecartEntity::SetDataIdDisplayOffset(const int data_id_display_offset)
146 {
147 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
148 metadata["data_id_display_offset"] = data_id_display_offset;
149 }
150
151 void AbstractMinecartEntity::SetDataIdCustomDisplay(const bool data_id_custom_display)
152 {
153 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
154 metadata["data_id_custom_display"] = data_id_custom_display;
155 }
156
157}
virtual bool IsAbstractMinecart() const override
void SetDataIdDisplayBlock(const int data_id_display_block)
void SetDataIdDisplayOffset(const int data_id_display_offset)
void SetDataIdCustomDisplay(const bool data_id_custom_display)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static const std::array< std::string, metadata_count > metadata_names
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1095
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:622
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
void SetDataIdHurt(const int data_id_hurt)
void SetDataIdDamage(const float data_id_damage)
float GetDataIdDamage() const
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
void SetDataIdHurtdir(const int data_id_hurtdir)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45