Botcraft 1.21.4
Loading...
Searching...
No Matches
FishingHookEntity.cpp
Go to the documentation of this file.
2
3#include <mutex>
4
5namespace Botcraft
6{
7 const std::array<std::string, FishingHookEntity::metadata_count> FishingHookEntity::metadata_names{ {
8 "data_hooked_entity",
9#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
10 "data_biting",
11#endif
12 } };
13
15 {
16 // Initialize all metadata with default values
18#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
19 SetDataBiting(false);
20#endif
21 }
22
27
28
29 std::string FishingHookEntity::GetName() const
30 {
31 return "fishing_bobber";
32 }
33
38
39
41 {
42 return "fishing_bobber";
43 }
44
49
51 {
52#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
54#else
56#endif
57
58 output["metadata"]["data_hooked_entity"] = GetDataHookedEntity();
59#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
60 output["metadata"]["data_biting"] = GetDataBiting();
61#endif
62
63 return output;
64 }
65
66
67 void FishingHookEntity::SetMetadataValue(const int index, const std::any& value)
68 {
69 if (index < hierarchy_metadata_count)
70 {
71#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
73#else
74 Entity::SetMetadataValue(index, value);
75#endif
76 }
78 {
79 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
81 }
82 }
83
85 {
86 std::shared_lock<std::shared_mutex> lock(entity_mutex);
87 return std::any_cast<int>(metadata.at("data_hooked_entity"));
88 }
89
90#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
92 {
93 std::shared_lock<std::shared_mutex> lock(entity_mutex);
94 return std::any_cast<bool>(metadata.at("data_biting"));
95 }
96#endif
97
98
99 void FishingHookEntity::SetDataHookedEntity(const int data_hooked_entity)
100 {
101 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
102 metadata["data_hooked_entity"] = data_hooked_entity;
103 }
104
105#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
106 void FishingHookEntity::SetDataBiting(const bool data_biting)
107 {
108 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
109 metadata["data_biting"] = data_biting;
110 }
111#endif
112
113
115 {
116 return 0.25;
117 }
118
120 {
121 return 0.25;
122 }
123
124}
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 void SetMetadataValue(const int index, const std::any &value) override
virtual std::string GetName() const override
void SetDataBiting(const bool data_biting)
virtual ProtocolCraft::Json::Value Serialize() const override
virtual EntityType GetType() const override
static const std::array< std::string, metadata_count > metadata_names
static constexpr int hierarchy_metadata_count
virtual double GetWidthImpl() const override
static std::string GetClassName()
static constexpr int metadata_count
virtual double GetHeightImpl() const override
void SetDataHookedEntity(const int data_hooked_entity)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45