Botcraft 1.21.5
Loading...
Searching...
No Matches
SnifferEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, SnifferEntity::metadata_count> SnifferEntity::metadata_names{ {
9 "data_state",
10 "data_drop_seed_at_tick",
11 } };
12
14 {
15 // Initialize all metadata with default values
16 SetDataState(0);
18
19 // Initialize all attributes with default values
22 }
23
28
29
30 std::string SnifferEntity::GetName() const
31 {
32 return "sniffer";
33 }
34
39
40
42 {
43 return "sniffer";
44 }
45
50
51
52
54 {
56
57 output["metadata"]["data_state"] = GetDataState();
58 output["metadata"]["data_drop_seed_at_tick"] = GetDataDropSeedAtTick();
59
60 return output;
61 }
62
63
64 void SnifferEntity::SetMetadataValue(const int index, const std::any& value)
65 {
66 if (index < hierarchy_metadata_count)
67 {
69 }
71 {
72 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
74 }
75 }
76
77
79 {
80 std::shared_lock<std::shared_mutex> lock(entity_mutex);
81 return std::any_cast<int>(metadata.at("data_state"));
82 }
83
85 {
86 std::shared_lock<std::shared_mutex> lock(entity_mutex);
87 return std::any_cast<int>(metadata.at("data_drop_seed_at_tick"));
88 }
89
90
91 void SnifferEntity::SetDataState(const int data_state)
92 {
93 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
94 metadata["data_state"] = data_state;
95 }
96
97 void SnifferEntity::SetDataDropSeedAtTick(const int data_drop_seed_at_tick)
98 {
99 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
100 metadata["data_drop_seed_at_tick"] = data_drop_seed_at_tick;
101 }
102
103
105 {
106 return 1.9;
107 }
108
110 {
111 return 1.75;
112 }
113
114}
115#endif
virtual void SetMetadataValue(const int index, const std::any &value) override
virtual ProtocolCraft::Json::Value Serialize() const override
std::shared_mutex entity_mutex
Definition Entity.hpp:259
std::map< std::string, std::any > metadata
Definition Entity.hpp:274
std::map< EntityAttribute::Type, EntityAttribute > attributes
static std::string GetClassName()
virtual std::string GetName() const override
virtual double GetHeightImpl() const override
static constexpr int hierarchy_metadata_count
virtual EntityType GetType() const override
void SetDataState(const int data_state)
static const std::array< std::string, metadata_count > metadata_names
int GetDataDropSeedAtTick() const
virtual ProtocolCraft::Json::Value Serialize() const override
static constexpr int metadata_count
virtual double GetWidthImpl() const override
virtual void SetMetadataValue(const int index, const std::any &value) override
static EntityType GetClassType()
void SetDataDropSeedAtTick(const int data_drop_seed_at_tick)
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45