Botcraft 1.21.4
Loading...
Searching...
No Matches
FireworkRocketEntity.cpp
Go to the documentation of this file.
2
3#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
5#endif
6
7#include <mutex>
8
9namespace Botcraft
10{
11 const std::array<std::string, FireworkRocketEntity::metadata_count> FireworkRocketEntity::metadata_names{ {
12 "data_id_fireworks_item",
13 "data_attached_to_target",
14#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
15 "data_shot_at_angle",
16#endif
17 } };
18
20 {
21 // Initialize all metadata with default values
22#if PROTOCOL_VERSION < 766 /* < 1.20.5 */
24#else
25 const static int item_id = AssetsManager::getInstance().GetItemID("minecraft:firework_rocket");
26 ProtocolCraft::Slot default_slot;
27 default_slot.SetItemId(item_id);
28 default_slot.SetItemCount(1);
29 SetDataIdFireworksItem(default_slot);
30#endif
32#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
33 SetDataAttachedToTarget(std::optional<int>());
34 SetDataShotAtAngle(false);
35#else
37#endif
38 }
39
44
45
47 {
48 return "firework_rocket";
49 }
50
55
56
58 {
59 return "firework_rocket";
60 }
61
66
67
69 {
70#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
72#else
74#endif
75
76 output["metadata"]["data_id_fireworks_item"] = GetDataIdFireworksItem().Serialize();
77#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
78 output["metadata"]["data_attached_to_target"] = GetDataAttachedToTarget() ? ProtocolCraft::Json::Value(GetDataAttachedToTarget().value()) : ProtocolCraft::Json::Value();
79 output["metadata"]["data_shot_at_angle"] = GetDataShotAtAngle();
80#else
81 output["metadata"]["data_attached_to_target"] = GetDataAttachedToTarget();
82#endif
83
84 return output;
85 }
86
87
88 void FireworkRocketEntity::SetMetadataValue(const int index, const std::any& value)
89 {
90 if (index < hierarchy_metadata_count)
91 {
92#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
94#else
95 Entity::SetMetadataValue(index, value);
96#endif
97 }
99 {
100 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
102 }
103 }
104
106 {
107 std::shared_lock<std::shared_mutex> lock(entity_mutex);
108 return std::any_cast<ProtocolCraft::Slot>(metadata.at("data_id_fireworks_item"));
109 }
110
111#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
113 {
114 std::shared_lock<std::shared_mutex> lock(entity_mutex);
115 return std::any_cast<std::optional<int>>(metadata.at("data_attached_to_target"));
116 }
117
119 {
120 std::shared_lock<std::shared_mutex> lock(entity_mutex);
121 return std::any_cast<bool>(metadata.at("data_shot_at_angle"));
122 }
123#else
125 {
126 std::shared_lock<std::shared_mutex> lock(entity_mutex);
127 return std::any_cast<int>(metadata.at("data_attached_to_target"));
128 }
129#endif
130
131
133 {
134 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
135 metadata["data_id_fireworks_item"] = data_id_fireworks_item;
136 }
137
138#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
139 void FireworkRocketEntity::SetDataAttachedToTarget(const std::optional<int>& data_attached_to_target)
140 {
141 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
142 metadata["data_attached_to_target"] = data_attached_to_target;
143 }
144
145 void FireworkRocketEntity::SetDataShotAtAngle(const bool data_shot_at_angle)
146 {
147 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
148 metadata["data_shot_at_angle"] = data_shot_at_angle;
149 }
150#else
151 void FireworkRocketEntity::SetDataAttachedToTarget(const int data_attached_to_target)
152 {
153 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
154 metadata["data_attached_to_target"] = data_attached_to_target;
155 }
156#endif
157
158
160 {
161 return 0.25;
162 }
163
165 {
166 return 0.25;
167 }
168
169}
static AssetsManager & getInstance()
ItemId GetItemID(const std::string &item_name) const
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
virtual double GetHeightImpl() const override
ProtocolCraft::Slot GetDataIdFireworksItem() const
virtual ProtocolCraft::Json::Value Serialize() const override
std::optional< int > GetDataAttachedToTarget() const
virtual double GetWidthImpl() const override
void SetDataShotAtAngle(const bool data_shot_at_angle)
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
void SetDataIdFireworksItem(const ProtocolCraft::Slot &data_id_fireworks_item)
virtual EntityType GetType() const override
void SetDataAttachedToTarget(const std::optional< int > &data_attached_to_target)
static constexpr int hierarchy_metadata_count
static const std::array< std::string, metadata_count > metadata_names
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
virtual Json::Value Serialize() const