Botcraft 1.21.4
Loading...
Searching...
No Matches
ThrownPotionEntity.cpp
Go to the documentation of this file.
2
3#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
5#endif
6
7#if PROTOCOL_VERSION < 579 /* < 1.16 */
8#include <mutex>
9#endif
10
11namespace Botcraft
12{
13#if PROTOCOL_VERSION < 579 /* < 1.16 */
14 const std::array<std::string, ThrownPotionEntity::metadata_count> ThrownPotionEntity::metadata_names{ {
15 "data_item_stack",
16 } };
17#endif
18
20 {
21 // Initialize all metadata with default values
22#if PROTOCOL_VERSION < 579 /* < 1.16 */
24#endif
25#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
26 static const int item_id = AssetsManager::getInstance().GetItemID("minecraft:splash_potion");
27 ProtocolCraft::Slot default_slot;
28 default_slot.SetItemId(item_id);
29 default_slot.SetItemCount(1);
30 SetDataItemStack(default_slot);
31#endif
32 }
33
38
39
40 std::string ThrownPotionEntity::GetName() const
41 {
42 return "potion";
43 }
44
49
50
52 {
53 return "potion";
54 }
55
60
61
62#if PROTOCOL_VERSION < 579 /* < 1.16 */
64 {
66
67 output["metadata"]["data_item_stack"] = GetDataItemStack().Serialize();
68
69 return output;
70 }
71
72
73 void ThrownPotionEntity::SetMetadataValue(const int index, const std::any& value)
74 {
75 if (index < hierarchy_metadata_count)
76 {
78 }
80 {
81 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
83 }
84 }
85
87 {
88 std::shared_lock<std::shared_mutex> lock(entity_mutex);
89 return std::any_cast<ProtocolCraft::Slot>(metadata.at("data_item_stack"));
90 }
91
92
94 {
95 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
96 metadata["data_item_stack"] = data_item_stack;
97 }
98#endif
99
100
102 {
103 return 0.25;
104 }
105
107 {
108 return 0.25;
109 }
110
111}
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
static const std::array< std::string, metadata_count > metadata_names
Definition Entity.hpp:61
std::shared_mutex entity_mutex
Definition Entity.hpp:253
std::map< std::string, std::any > metadata
Definition Entity.hpp:268
static const std::array< std::string, metadata_count > metadata_names
void SetDataItemStack(const ProtocolCraft::Slot &data_item_stack)
static constexpr int hierarchy_metadata_count
virtual EntityType GetType() const override
virtual double GetWidthImpl() const override
static constexpr int metadata_count
virtual double GetHeightImpl() const override
virtual std::string GetName() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
virtual Json::Value Serialize() const