Botcraft 1.21.8
Loading...
Searching...
No Matches
PhantomEntity.cpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
3
4#include <mutex>
5
6namespace Botcraft
7{
8 const std::array<std::string, PhantomEntity::metadata_count> PhantomEntity::metadata_names{ {
9 "id_size",
10 } };
11
13 {
14 // Initialize all metadata with default values
15 SetIdSize(0);
16 }
17
22
23
24 std::string PhantomEntity::GetName() const
25 {
26 return "phantom";
27 }
28
33
34
36 {
37 return "phantom";
38 }
39
44
45
47 {
48#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
49 ProtocolCraft::Json::Value output = FlyingMobEntity::Serialize();
50#else
52#endif
53
54 output["metadata"]["id_size"] = GetIdSize();
55
56 return output;
57 }
58
59
60 void PhantomEntity::SetMetadataValue(const int index, const std::any& value)
61 {
62 if (index < hierarchy_metadata_count)
63 {
64#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
65 FlyingMobEntity::SetMetadataValue(index, value);
66#else
67 MobEntity::SetMetadataValue(index, value);
68#endif
69 }
71 {
72 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
74 }
75 }
76
78 {
79 std::shared_lock<std::shared_mutex> lock(entity_mutex);
80 return std::any_cast<int>(metadata.at("id_size"));
81 }
82
83
84 void PhantomEntity::SetIdSize(const int id_size)
85 {
86 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
87 metadata["id_size"] = id_size;
88 }
89
90
92 {
93 return 0.9;
94 }
95
97 {
98 return 0.5;
99 }
100
101}
102#endif
std::shared_mutex entity_mutex
Definition Entity.hpp:261
std::map< std::string, std::any > metadata
Definition Entity.hpp:276
virtual ProtocolCraft::Json::Value Serialize() const override
Definition MobEntity.cpp:34
virtual void SetMetadataValue(const int index, const std::any &value) override
Definition MobEntity.cpp:49
virtual EntityType GetType() const override
static const std::array< std::string, metadata_count > metadata_names
virtual void SetMetadataValue(const int index, const std::any &value) override
static constexpr int metadata_count
virtual double GetHeightImpl() const override
virtual double GetWidthImpl() const override
static std::string GetClassName()
virtual std::string GetName() const override
static constexpr int hierarchy_metadata_count
void SetIdSize(const int id_size)
static EntityType GetClassType()
virtual ProtocolCraft::Json::Value Serialize() const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45