Botcraft 1.21.5
Loading...
Searching...
No Matches
ThrownPotionEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
3
4#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
6#endif
7
8#if PROTOCOL_VERSION < 579 /* < 1.16 */
9#include <mutex>
10#endif
11
12namespace Botcraft
13{
14#if PROTOCOL_VERSION < 579 /* < 1.16 */
15 const std::array<std::string, ThrownPotionEntity::metadata_count> ThrownPotionEntity::metadata_names{ {
16 "data_item_stack",
17 } };
18#endif
19
20 ThrownPotionEntity::ThrownPotionEntity()
21 {
22 // Initialize all metadata with default values
23#if PROTOCOL_VERSION < 579 /* < 1.16 */
24 SetDataItemStack(ProtocolCraft::Slot());
25#endif
26#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
27 static const int item_id = AssetsManager::getInstance().GetItemID("minecraft:splash_potion");
28 ProtocolCraft::Slot default_slot;
29 default_slot.SetItemId(item_id);
30 default_slot.SetItemCount(1);
31 SetDataItemStack(default_slot);
32#endif
33 }
34
35 ThrownPotionEntity::~ThrownPotionEntity()
36 {
37
38 }
39
40
41 std::string ThrownPotionEntity::GetName() const
42 {
43 return "potion";
44 }
45
46 EntityType ThrownPotionEntity::GetType() const
47 {
48 return EntityType::ThrownPotion;
49 }
50
51
52 std::string ThrownPotionEntity::GetClassName()
53 {
54 return "potion";
55 }
56
57 EntityType ThrownPotionEntity::GetClassType()
58 {
59 return EntityType::ThrownPotion;
60 }
61
62
63#if PROTOCOL_VERSION < 579 /* < 1.16 */
64 ProtocolCraft::Json::Value ThrownPotionEntity::Serialize() const
65 {
67
68 output["metadata"]["data_item_stack"] = GetDataItemStack().Serialize();
69
70 return output;
71 }
72
73
74 void ThrownPotionEntity::SetMetadataValue(const int index, const std::any& value)
75 {
76 if (index < hierarchy_metadata_count)
77 {
79 }
80 else if (index - hierarchy_metadata_count < metadata_count)
81 {
82 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
83 metadata[metadata_names[index - hierarchy_metadata_count]] = value;
84 }
85 }
86
87 ProtocolCraft::Slot ThrownPotionEntity::GetDataItemStack() const
88 {
89 std::shared_lock<std::shared_mutex> lock(entity_mutex);
90 return std::any_cast<ProtocolCraft::Slot>(metadata.at("data_item_stack"));
91 }
92
93
94 void ThrownPotionEntity::SetDataItemStack(const ProtocolCraft::Slot& data_item_stack)
95 {
96 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
97 metadata["data_item_stack"] = data_item_stack;
98 }
99#endif
100
101
102 double ThrownPotionEntity::GetWidthImpl() const
103 {
104 return 0.25;
105 }
106
107 double ThrownPotionEntity::GetHeightImpl() const
108 {
109 return 0.25;
110 }
111
112}
113#endif
static AssetsManager & getInstance()
ItemId GetItemID(const std::string &item_name) const
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1151
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:678
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45