Botcraft 26.3
Loading...
Searching...
No Matches
Entity.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <any>
4#include <array>
5#include <chrono>
6#include <map>
7#include <memory>
8#include <mutex>
9#include <optional>
10#include <shared_mutex>
11#include <string_view>
12
13#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
15#endif
18
20
23
24#if USE_GUI
26#endif
27
28namespace Botcraft
29{
30 enum class EntityType;
31#if PROTOCOL_VERSION < 458 /* < 1.14 */
32 enum class ObjectEntityType;
33#endif
34
36 {
38 unsigned char amplifier;
39 std::chrono::steady_clock::time_point end;
40 };
41
42 enum class EntitySharedFlagsId : char
43 {
44 OnFire = 0,
45 ShiftKeyDown = 1,
46 // 2 is unused? Maybe in previous versions
47 Sprinting = 3,
48 Swimming = 4,
49 Invisible = 5,
50 Glowing = 6,
51 FallFlying = 7
52 };
53
54 class Entity
55 {
56 private:
57 static constexpr std::array metadata_names{
58 std::string_view("data_shared_flags_id"),
59 std::string_view("data_air_supply_id"),
60 std::string_view("data_custom_name"),
61 std::string_view("data_custom_name_visible"),
62 std::string_view("data_silent"),
63 std::string_view("data_no_gravity"),
64#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
65 std::string_view("data_pose"),
66#endif
67#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
68 std::string_view("data_ticks_frozen"),
69#endif
70 };
71 protected:
72 static constexpr int metadata_count = static_cast<int>(metadata_names.size());
73 static constexpr int hierarchy_metadata_count = 0;
74
75 public:
76 Entity();
77 virtual ~Entity();
78
79 // Object related stuff
80 virtual std::string GetName() const = 0;
81 virtual EntityType GetType() const = 0;
82 AABB GetCollider() const;
83 double GetWidth() const;
84 double GetHeight() const;
85
86 protected:
87 // Metadata stuff
88 template <size_t N>
89 static constexpr int FindMetadataIndex(const std::array<std::string_view, N>& names, const std::string_view name)
90 {
91 for (size_t i = 0; i < N; ++i)
92 {
93 if (names[i] == name)
94 {
95 return static_cast<int>(i);
96 }
97 }
98 return -1;
99 }
100
101 template <typename T>
102 T GetMetadataImpl(const int index) const
103 {
104 return std::any_cast<T>(metadata.at(index));
105 }
106
107 template <typename T>
108 T GetMetadata(const int index) const
109 {
110 std::shared_lock<std::shared_mutex> lock(entity_mutex);
111 return GetMetadataImpl<T>(index);
112 }
113
114 void SetMetadataImpl(const int index, const std::any& value);
115 void SetMetadata(const int index, const std::any& value);
116 virtual void OnMetadataChangedImpl(const int index);
117
118
119 public:
120 void LoadMetadataFromRawArray(const std::vector<unsigned char>& data);
121
122 char GetDataSharedFlagsId() const;
123 bool GetDataSharedFlagsId(const EntitySharedFlagsId id) const;
124 int GetDataAirSupplyId() const;
125#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
126 std::optional<ProtocolCraft::Chat> GetDataCustomName() const;
127#else
128 std::string GetDataCustomName() const;
129#endif
130 bool GetDataCustomNameVisible() const;
131 bool GetDataSilent() const;
132 bool GetDataNoGravity() const;
133#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
134 Pose GetDataPose() const;
135#endif
136#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
137 int GetDataTicksFrozen() const;
138#endif
139
140
141 void SetDataSharedFlagsId(const char data_shared_flags_id);
142 void SetDataSharedFlagsId(const EntitySharedFlagsId id, const bool b);
143 void SetDataAirSupplyId(const int data_air_supply_id);
144#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
145 void SetDataCustomName(const std::optional<ProtocolCraft::Chat>& data_custom_name);
146#else
147 void SetDataCustomName(const std::string& data_custom_name);
148#endif
149 void SetDataCustomNameVisible(const bool data_custom_name_visible);
150 void SetDataSilent(const bool data_silent);
151 void SetDataNoGravity(const bool data_no_gravity);
152#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
153 void SetDataPose(const Pose data_pose);
154#endif
155#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
156 void SetDataTicksFrozen(const int data_ticks_frozen);
157#endif
158
159
160 // Generic properties getter
161 int GetEntityID() const;
164 double GetX() const;
165 double GetY() const;
166 double GetZ() const;
167 float GetYaw() const;
168 float GetPitch() const;
170 double GetSpeedX() const;
171 double GetSpeedY() const;
172 double GetSpeedZ() const;
173 bool GetOnGround() const;
174 std::map<EquipmentSlot, ProtocolCraft::Slot> GetEquipments() const;
176 std::vector<EntityEffect> GetEffects() const;
177#if USE_GUI
178 std::vector<Renderer::Face> GetFaces(const bool reset_uptodate_status);
179 bool GetAreRenderedFacesUpToDate() const;
180#endif
181
182 // Generic properties setter
183 void SetEntityID(const int entity_id_);
184 void SetUUID(const ProtocolCraft::UUID& uuid_);
185 virtual void SetPosition(const Vector3<double>& position_);
186 virtual void SetX(const double x_);
187 virtual void SetY(const double y_);
188 virtual void SetZ(const double z_);
189 virtual void SetYaw(const float yaw_);
190 virtual void SetPitch(const float pitch_);
191 void AddSpeed(const Vector3<double>& delta);
192 void SetSpeed(const Vector3<double>& speed_);
193 void SetSpeedX(const double speed_x_);
194 void SetSpeedY(const double speed_y_);
195 void SetSpeedZ(const double speed_z_);
196 void SetOnGround(const bool on_ground_);
197 void SetEquipment(const EquipmentSlot slot, const ProtocolCraft::Slot& item);
198 void SetEffects(const std::vector<EntityEffect>& effects_);
199 void AddEffect(const EntityEffect& effect);
200 void RemoveEffect(const EntityEffectType type);
201#if USE_GUI
202 void SetAreRenderedFacesUpToDate(const bool are_rendered_faces_up_to_date_);
203#endif
204
205
206 // In case it's needed one day, could be useful
208
209
210 virtual bool IsLocalPlayer() const;
211 virtual bool IsRemotePlayer() const;
212 // Can be used to know if an entity has a certain virtual type as ancestor
213 virtual bool IsLivingEntity() const;
214 virtual bool IsAbstractArrow() const;
215 virtual bool IsAnimal() const;
216 virtual bool IsAmbientCreature() const;
217 virtual bool IsMonster() const;
218#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
219 virtual bool IsDisplay() const;
220#endif
221#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
222 virtual bool IsVehicle() const;
223#endif
224 virtual bool IsTamableAnimal() const;
225 virtual bool IsAbstractSchoolingFish() const;
226 virtual bool IsWaterAnimal() const;
227 virtual bool IsAbstractChestedHorse() const;
228 virtual bool IsAbstractHurtingProjectile() const;
229 virtual bool IsMob() const;
230 virtual bool IsSpellcasterIllager() const;
231#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
232 virtual bool IsProjectile() const;
233#endif
234#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
235 virtual bool IsFlyingMob() const;
236#endif
237 virtual bool IsAbstractHorse() const;
238 virtual bool IsAbstractGolem() const;
239 virtual bool IsHangingEntity() const;
240 virtual bool IsFireball() const;
241 virtual bool IsAbstractMinecart() const;
242#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
243 virtual bool IsAbstractCow() const;
244#endif
245 virtual bool IsAbstractMinecartContainer() const;
246 virtual bool IsShoulderRidingEntity() const;
247#if PROTOCOL_VERSION > 736 /* > 1.16.1 */
248 virtual bool IsAbstractPiglin() const;
249#endif
250 virtual bool IsAbstractIllager() const;
251#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
252 virtual bool IsAbstractThrownPotion() const;
253#endif
254 virtual bool IsAbstractFish() const;
255#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
256 virtual bool IsRaider() const;
257#endif
258 virtual bool IsAbstractSkeleton() const;
259 virtual bool IsThrowableItemProjectile() const;
260#if PROTOCOL_VERSION > 477 /* > 1.14 */
261 virtual bool IsAbstractVillager() const;
262#endif
263 virtual bool IsAgeableMob() const;
264 virtual bool IsPathfinderMob() const;
265#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
266 virtual bool IsPatrollingMonster() const;
267#endif
268 virtual bool IsThrowableProjectile() const;
269#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
270 virtual bool IsAbstractWindCharge() const;
271#endif
272#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
273 virtual bool IsBlockAttachedEntity() const;
274#endif
275#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
276 virtual bool IsAbstractBoat() const;
277 virtual bool IsAbstractChestBoat() const;
278 virtual bool IsAgeableWaterCreature() const;
279 virtual bool IsBoat() const;
280 virtual bool IsChestBoat() const;
281 virtual bool IsChestRaft() const;
282 virtual bool IsRaft() const;
283#endif
284#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
285 virtual bool IsAvatar() const;
286#endif
287#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
288 virtual bool IsAbstractNautilus() const;
289#endif
290#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
291 virtual bool IsAbstractCubeMob() const;
292#endif
293
294
295 // Factory stuff
296 static std::shared_ptr<Entity> CreateEntity(const EntityType type);
297#if PROTOCOL_VERSION < 458 /* < 1.14 */
298 static std::shared_ptr<Entity> CreateObjectEntity(const ObjectEntityType type);
299#endif
300
301
302 protected:
303#if USE_GUI
304 virtual void InitializeFaces();
305 void OnSizeUpdated();
306#endif
307 char GetDataSharedFlagsIdImpl() const;
309 void SetDataSharedFlagsIdImpl(const char data_shared_flags_id);
310 void SetDataSharedFlagsIdImpl(const EntitySharedFlagsId id, const bool b);
311#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
312 Pose GetDataPoseImpl() const;
313 void SetDataPoseImpl(const Pose data_pose);
314#endif
315 AABB GetColliderImpl() const;
316 virtual double GetWidthImpl() const;
317 virtual double GetHeightImpl() const;
318
319 protected:
320 mutable std::shared_mutex entity_mutex;
321
325 float yaw;
326 float pitch;
329 /// @brief Items on this entity. Note that for the local player
330 /// this will **NOT** be populated. Check corresponding
331 /// player inventory slots instead.
332 std::map<EquipmentSlot, ProtocolCraft::Slot> equipments;
333 std::vector<EntityEffect> effects;
334
335 std::vector<std::any> metadata;
336
337#if USE_GUI
338 // All the faces of this model
339 std::vector<FaceDescriptor> face_descriptors;
340 std::vector<Renderer::Face> faces;
341
343#endif
344 };
345
346 // Can be used inside any entity-derived class to get the index of a given key
347#define BOTCRAFT_ENTITY_METADATA_INDEX(name) \
348 ([]() { \
349 constexpr int i = FindMetadataIndex(metadata_names, name); \
350 static_assert(i >= 0, "Unknown metadata " name); \
351 return hierarchy_metadata_count + i; \
352 }())
353
354 enum class EntityType
355 {
356 None = -1,
357#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
358#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
361#endif
362#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
363 Allay,
364#endif
366#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
367 Armadillo,
368#endif
370 Arrow,
371#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
372 Axolotl,
373#endif
374#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
375 ChestRaft,
376 Raft,
377#endif
378 Bat,
379#if PROTOCOL_VERSION > 498 /* > 1.14.4 */
380 Bee,
381#endif
382#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
383 BirchBoat,
385#endif
386 Blaze,
387#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
389#endif
390#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
391 Boat,
392#endif
393#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
394 Bogged,
395#endif
396#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
397 Breeze,
398#endif
399#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
401#endif
402#if PROTOCOL_VERSION > 758 /* > 1.18.2 */ && PROTOCOL_VERSION < 762 /* < 1.19.4 */
403 ChestBoat,
404#endif
405#if PROTOCOL_VERSION > 404 /* > 1.13.2 */ && PROTOCOL_VERSION < 762 /* < 1.19.4 */
406 Cat,
407#endif
408#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
409 Camel,
410#endif
411#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
412 CamelHusk,
413#endif
414#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
415 Cat,
416#endif
418#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
421#endif
422#if PROTOCOL_VERSION > 761 /* > 1.19.3 */ && PROTOCOL_VERSION < 768 /* < 1.21.2 */
423 ChestBoat,
424#endif
425#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
427#endif
428 Chicken,
429 Cod,
430#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
432#endif
433#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
435#endif
436 Cow,
437#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
438 Creaking,
439#endif
440#if PROTOCOL_VERSION > 767 /* > 1.21.1 */ && PROTOCOL_VERSION < 769 /* < 1.21.4 */
441 CreakingTransient,
442#endif
443 Creeper,
444#if PROTOCOL_VERSION > 776 /* > 26.2 */
445 Cushion,
446#endif
447#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
450#endif
451#if PROTOCOL_VERSION < 735 /* < 1.16 */
452 Donkey,
453#endif
454 Dolphin,
455#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
456 Donkey,
457#endif
459 Drowned,
460#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
461 ThrownEgg,
462#endif
464#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
467#endif
468#if PROTOCOL_VERSION > 761 /* > 1.19.3 */ && PROTOCOL_VERSION < 768 /* < 1.21.2 */
470#endif
471 EnderMan,
472 Endermite,
473#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
477#endif
478#if PROTOCOL_VERSION < 735 /* < 1.16 */
480#endif
481 Evoker,
482#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
484#endif
485#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
487#endif
491#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
493#endif
495#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
496 Fox,
497#endif
498#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
499 Frog,
500#endif
501#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
503#endif
504 Ghast,
505#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
507#endif
508 Giant,
509#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
511 GlowSquid,
512 Goat,
513#endif
514 Guardian,
515#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
516 Hoglin,
517#endif
518#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
520#endif
521 Horse,
522 Husk,
524#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
526#endif
527#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
528 IronGolem,
529#endif
531#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
533#endif
534 ItemFrame,
535#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
538#endif
539#if PROTOCOL_VERSION > 765 /* > 1.20.4 */ && PROTOCOL_VERSION < 768 /* < 1.21.2 */
541#endif
542#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
544#endif
546#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
548#endif
549 Llama,
550 LlamaSpit,
551 MagmaCube,
552#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
555#endif
556#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
557 Mannequin,
558#endif
559#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
560 Marker,
561#endif
562 Minecart,
563#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
570 Mule,
571#endif
573#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
574 Mule,
575#endif
576#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
577 Nautilus,
578#endif
579#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
580 OakBoat,
582#endif
583 Ocelot,
584#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
586#endif
587 Painting,
588#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
591#endif
592#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
593 Panda,
594#endif
595#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
596 Parched,
597#endif
598 Parrot,
599#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
600 Phantom,
601#endif
602 Pig,
603#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
604 Piglin,
605#endif
606#if PROTOCOL_VERSION > 736 /* > 1.16.1 */
608#endif
609#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
610 Pillager,
611#endif
612#if PROTOCOL_VERSION < 735 /* < 1.16 */
614 PigZombie,
615#endif
616 PolarBear,
617#if PROTOCOL_VERSION > 776 /* > 26.2 */
620#endif
621#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
624#endif
625#if PROTOCOL_VERSION > 761 /* > 1.19.3 */ && PROTOCOL_VERSION < 770 /* < 1.21.5 */
626 ThrownPotion,
627#endif
628#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
629 PrimedTnt,
630#endif
631#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
633#endif
634 Rabbit,
635#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
636 Ravager,
637#endif
638 Salmon,
639 Sheep,
640 Shulker,
643 Skeleton,
645 Slime,
647#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
648 Sniffer,
649#endif
650#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
651 SnowGolem,
652#endif
653 Snowball,
654#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
655 SnowGolem,
656#endif
657#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
659#endif
661 Spider,
662#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
665#endif
666 Squid,
667 Stray,
668#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
669 Strider,
670#endif
671#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
673#endif
674#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
675 Tadpole,
676#endif
677#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
679 PrimedTnt,
681#endif
682#if PROTOCOL_VERSION > 404 /* > 1.13.2 */ && PROTOCOL_VERSION < 735 /* < 1.16 */
684#endif
685#if PROTOCOL_VERSION < 735 /* < 1.16 */
687 Turtle,
688#endif
689#if PROTOCOL_VERSION < 762 /* < 1.19.4 */
690 ThrownEgg,
693 ThrownPotion,
694#endif
695#if PROTOCOL_VERSION > 404 /* > 1.13.2 */ && PROTOCOL_VERSION < 762 /* < 1.19.4 */
697#endif
698#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
700#endif
701#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
703#endif
704#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
706 Turtle,
707#endif
708 Vex,
709 Villager,
710#if PROTOCOL_VERSION < 735 /* < 1.16 */
711 IronGolem,
712#endif
714#if PROTOCOL_VERSION > 404 /* > 1.13.2 */ && PROTOCOL_VERSION < 735 /* < 1.16 */
715 Pillager,
716#endif
717#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
719#endif
720#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
721 Warden,
722#endif
723#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
725#endif
726 Witch,
730 Wolf,
731#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
732 Zoglin,
733#endif
734 Zombie,
736#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
738#endif
740#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
742#endif
743#if PROTOCOL_VERSION < 735 /* < 1.16 */
744 Phantom,
745#endif
746#if PROTOCOL_VERSION > 404 /* > 1.13.2 */ && PROTOCOL_VERSION < 735 /* < 1.16 */
747 Ravager,
748#endif
749#if PROTOCOL_VERSION < 735 /* < 1.16 */
751#endif
752 Player,
754#if PROTOCOL_VERSION < 477 /* < 1.14 */
756#endif
757#else
758 FishingHook = -3,
759 Player = -2,
760 ItemEntity = 1,
761 ExperienceOrb = 2,
762 AreaEffectCloud = 3,
763 ElderGuardian = 4,
764 WitherSkeleton = 5,
765 Stray = 6,
766 ThrownEgg = 7,
768 Painting = 9,
769 Arrow = 10,
770 Snowball = 11,
771 LargeFireball = 12,
772 SmallFireball = 13,
773 ThrownEnderpearl = 14,
774 EyeOfEnder = 15,
775 ThrownPotion = 16,
777 ItemFrame = 18,
778 WitherSkull = 19,
779 PrimedTnt = 20,
782 Husk = 23,
783 SpectralArrow = 24,
784 ShulkerBullet = 25,
785 DragonFireball = 26,
786 ZombieVillager = 27,
787 SkeletonHorse = 28,
788 ZombieHorse = 29,
789 ArmorStand = 30,
790 Donkey = 31,
791 Mule = 32,
792 EvokerFangs = 33,
793 Evoker = 34,
794 Vex = 35,
795 Vindicator = 36,
796 Illusioner = 37,
798 Boat = 41,
799 Minecart = 42,
800 MinecartChest = 43,
801 MinecartFurnace = 44,
802 MinecartTNT = 45,
803 MinecartHopper = 46,
804 MinecartSpawner = 47,
805 Creeper = 50,
806 Skeleton = 51,
807 Spider = 52,
808 Giant = 53,
809 Zombie = 54,
810 Slime = 55,
811 Ghast = 56,
812 PigZombie = 57,
813 EnderMan = 58,
814 CaveSpider = 59,
815 Silverfish = 60,
816 Blaze = 61,
817 MagmaCube = 62,
818 EnderDragon = 63,
819 WitherBoss = 64,
820 Bat = 65,
821 Witch = 66,
822 Endermite = 67,
823 Guardian = 68,
824 Shulker = 69,
825 Pig = 90,
826 Sheep = 91,
827 Cow = 92,
828 Chicken = 93,
829 Squid = 94,
830 Wolf = 95,
831 MushroomCow = 96,
832 SnowGolem = 97,
833 Ocelot = 98,
834 IronGolem = 99,
835 Horse = 100,
836 Rabbit = 101,
837 PolarBear = 102,
838 Llama = 103,
839 LlamaSpit = 104,
840 Parrot = 105,
841 Villager = 120,
842 EndCrystal = 200,
843#endif
845 };
846
847#if PROTOCOL_VERSION < 458 /* < 1.14 */
848 enum class ObjectEntityType
849 {
850 None = -1,
851 Boat = 1,
852 ItemEntity = 2,
853 AreaEffectCloud = 3,
854 PrimedTnt = 50,
855 EndCrystal = 51,
856 Arrow = 60,
857 Snowball = 61,
858 ThrownEgg = 62,
859 LargeFireball = 63,
860 SmallFireball = 64,
861 ThrownEnderpearl = 65,
862 WitherSkull = 66,
863 ShulkerBullet = 67,
864 LlamaSpit = 68,
865 FallingBlockEntity = 70,
866 ItemFrame = 71,
867 EyeOfEnder = 72,
868 ThrownPotion = 73,
870 FireworkRocketEntity = 76,
871 LeashFenceKnotEntity = 77,
872 ArmorStand = 78,
873 EvokerFangs = 79,
874 FishingHook = 90,
875 SpectralArrow = 91,
876 DragonFireball = 93,
877#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
878 ThrownTrident = 94,
879#endif
881 };
882#endif
883}
int GetDataTicksFrozen() const
Definition Entity.cpp:848
void OnSizeUpdated()
Definition Entity.cpp:2179
void SetMetadata(const int index, const std::any &value)
Definition Entity.cpp:366
virtual EntityType GetType() const =0
bool GetOnGround() const
Definition Entity.cpp:986
ProtocolCraft::UUID uuid
Definition Entity.hpp:323
virtual double GetHeightImpl() const
Definition Entity.cpp:2248
void SetDataSilent(const bool data_silent)
Definition Entity.cpp:889
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1246
void SetDataPose(const Pose data_pose)
Definition Entity.cpp:900
std::map< EquipmentSlot, ProtocolCraft::Slot > equipments
Items on this entity.
Definition Entity.hpp:332
virtual void SetY(const double y_)
Definition Entity.cpp:1088
double GetZ() const
Definition Entity.cpp:944
virtual bool IsAbstractChestedHorse() const
Definition Entity.cpp:1352
virtual bool IsWaterAnimal() const
Definition Entity.cpp:1347
void SetEffects(const std::vector< EntityEffect > &effects_)
Definition Entity.cpp:1194
void SetDataAirSupplyId(const int data_air_supply_id)
Definition Entity.cpp:867
void SetDataSharedFlagsIdImpl(const char data_shared_flags_id)
Definition Entity.cpp:2205
Vector3< double > GetSpeed() const
Definition Entity.cpp:962
void SetUUID(const ProtocolCraft::UUID &uuid_)
Definition Entity.cpp:1047
std::map< EquipmentSlot, ProtocolCraft::Slot > GetEquipments() const
Definition Entity.cpp:992
Vector3< double > speed
Definition Entity.hpp:327
virtual bool IsAbstractArrow() const
Definition Entity.cpp:1303
virtual bool IsAbstractSkeleton() const
Definition Entity.cpp:1459
virtual bool IsAbstractPiglin() const
Definition Entity.cpp:1429
int GetEntityID() const
Definition Entity.cpp:914
virtual bool IsLocalPlayer() const
Definition Entity.cpp:1288
double GetHeight() const
Definition Entity.cpp:349
std::vector< EntityEffect > effects
Definition Entity.hpp:333
char GetDataSharedFlagsIdImpl() const
Definition Entity.cpp:2195
virtual bool IsRemotePlayer() const
Definition Entity.cpp:1293
virtual bool IsAbstractNautilus() const
Definition Entity.cpp:1557
bool GetDataSilent() const
Definition Entity.cpp:830
void SetDataPoseImpl(const Pose data_pose)
Definition Entity.cpp:2227
double GetSpeedX() const
Definition Entity.cpp:968
virtual bool IsAbstractBoat() const
Definition Entity.cpp:1513
virtual bool IsAbstractHurtingProjectile() const
Definition Entity.cpp:1357
ProtocolCraft::UUID GetUUID() const
Definition Entity.cpp:920
void AddSpeed(const Vector3< double > &delta)
Definition Entity.cpp:1152
double GetY() const
Definition Entity.cpp:938
virtual bool IsAbstractSchoolingFish() const
Definition Entity.cpp:1342
void SetSpeed(const Vector3< double > &speed_)
Definition Entity.cpp:1158
virtual bool IsHangingEntity() const
Definition Entity.cpp:1396
bool GetAreRenderedFacesUpToDate() const
Definition Entity.cpp:1033
virtual bool IsSpellcasterIllager() const
Definition Entity.cpp:1367
virtual bool IsBlockAttachedEntity() const
Definition Entity.cpp:1506
T GetMetadataImpl(const int index) const
Definition Entity.hpp:102
static std::shared_ptr< Entity > CreateEntity(const EntityType type)
Definition Entity.cpp:1571
static constexpr int hierarchy_metadata_count
Definition Entity.hpp:73
virtual bool IsAbstractThrownPotion() const
Definition Entity.cpp:1441
AABB GetCollider() const
Definition Entity.cpp:337
bool are_rendered_faces_up_to_date
Definition Entity.hpp:342
virtual double GetWidthImpl() const
Definition Entity.cpp:2243
virtual void SetZ(const double z_)
Definition Entity.cpp:1104
void SetEquipment(const EquipmentSlot slot, const ProtocolCraft::Slot &item)
Definition Entity.cpp:1188
std::vector< Renderer::Face > faces
Definition Entity.hpp:340
virtual bool IsLivingEntity() const
Definition Entity.cpp:1298
virtual bool IsChestBoat() const
Definition Entity.cpp:1533
double GetWidth() const
Definition Entity.cpp:343
virtual ~Entity()
Definition Entity.cpp:331
virtual bool IsPatrollingMonster() const
Definition Entity.cpp:1487
virtual bool IsProjectile() const
Definition Entity.cpp:1373
int GetDataAirSupplyId() const
Definition Entity.cpp:808
std::vector< EntityEffect > GetEffects() const
Definition Entity.cpp:1004
virtual bool IsAbstractMinecart() const
Definition Entity.cpp:1406
virtual bool IsAvatar() const
Definition Entity.cpp:1550
virtual bool IsDisplay() const
Definition Entity.cpp:1324
void SetSpeedY(const double speed_y_)
Definition Entity.cpp:1170
virtual bool IsAbstractMinecartContainer() const
Definition Entity.cpp:1418
void SetDataCustomName(const std::optional< ProtocolCraft::Chat > &data_custom_name)
Definition Entity.cpp:873
virtual bool IsAmbientCreature() const
Definition Entity.cpp:1313
virtual bool IsFireball() const
Definition Entity.cpp:1401
Pose GetDataPose() const
Definition Entity.cpp:841
std::shared_mutex entity_mutex
Definition Entity.hpp:320
void SetOnGround(const bool on_ground_)
Definition Entity.cpp:1182
virtual bool IsAnimal() const
Definition Entity.cpp:1308
std::vector< Renderer::Face > GetFaces(const bool reset_uptodate_status)
Definition Entity.cpp:1012
void SetSpeedX(const double speed_x_)
Definition Entity.cpp:1164
virtual bool IsAbstractFish() const
Definition Entity.cpp:1447
virtual bool IsAbstractCubeMob() const
Definition Entity.cpp:1564
virtual bool IsAgeableMob() const
Definition Entity.cpp:1476
virtual void SetX(const double x_)
Definition Entity.cpp:1072
std::vector< std::any > metadata
Definition Entity.hpp:335
virtual bool IsAbstractVillager() const
Definition Entity.cpp:1470
virtual void InitializeFaces()
Definition Entity.cpp:2097
virtual bool IsThrowableProjectile() const
Definition Entity.cpp:1493
virtual bool IsAbstractWindCharge() const
Definition Entity.cpp:1499
AABB GetColliderImpl() const
Definition Entity.cpp:2233
void SetDataSharedFlagsId(const char data_shared_flags_id)
Definition Entity.cpp:855
char GetDataSharedFlagsId() const
Definition Entity.cpp:796
virtual bool IsMob() const
Definition Entity.cpp:1362
virtual void SetYaw(const float yaw_)
Definition Entity.cpp:1120
virtual bool IsPathfinderMob() const
Definition Entity.cpp:1481
ProtocolCraft::Slot GetEquipment(const EquipmentSlot slot) const
Definition Entity.cpp:998
T GetMetadata(const int index) const
Definition Entity.hpp:108
void SetDataCustomNameVisible(const bool data_custom_name_visible)
Definition Entity.cpp:884
virtual bool IsVehicle() const
Definition Entity.cpp:1331
double GetSpeedY() const
Definition Entity.cpp:974
double GetSpeedZ() const
Definition Entity.cpp:980
virtual std::string GetName() const =0
Pose GetDataPoseImpl() const
Definition Entity.cpp:2222
static constexpr std::array metadata_names
Definition Entity.hpp:57
virtual void OnMetadataChangedImpl(const int index)
Definition Entity.cpp:372
virtual bool IsRaider() const
Definition Entity.cpp:1453
virtual void SetPitch(const float pitch_)
Definition Entity.cpp:1136
virtual bool IsThrowableItemProjectile() const
Definition Entity.cpp:1464
void SetEntityID(const int entity_id_)
Definition Entity.cpp:1041
virtual bool IsMonster() const
Definition Entity.cpp:1318
virtual bool IsTamableAnimal() const
Definition Entity.cpp:1337
void SetDataNoGravity(const bool data_no_gravity)
Definition Entity.cpp:894
bool GetDataCustomNameVisible() const
Definition Entity.cpp:825
virtual bool IsAbstractIllager() const
Definition Entity.cpp:1435
virtual bool IsAbstractHorse() const
Definition Entity.cpp:1386
void SetMetadataImpl(const int index, const std::any &value)
Definition Entity.cpp:356
Vector3< double > position
Definition Entity.hpp:324
virtual bool IsAbstractCow() const
Definition Entity.cpp:1412
virtual bool IsAbstractChestBoat() const
Definition Entity.cpp:1518
void AddEffect(const EntityEffect &effect)
Definition Entity.cpp:1200
virtual bool IsChestRaft() const
Definition Entity.cpp:1538
virtual bool IsAbstractGolem() const
Definition Entity.cpp:1391
float GetYaw() const
Definition Entity.cpp:950
virtual bool IsAgeableWaterCreature() const
Definition Entity.cpp:1523
double GetX() const
Definition Entity.cpp:932
bool GetDataNoGravity() const
Definition Entity.cpp:835
void SetAreRenderedFacesUpToDate(const bool are_rendered_faces_up_to_date_)
Definition Entity.cpp:1238
Vector3< double > GetPosition() const
Definition Entity.cpp:926
static constexpr int FindMetadataIndex(const std::array< std::string_view, N > &names, const std::string_view name)
Definition Entity.hpp:89
void SetSpeedZ(const double speed_z_)
Definition Entity.cpp:1176
static constexpr int metadata_count
Definition Entity.hpp:72
std::vector< FaceDescriptor > face_descriptors
Definition Entity.hpp:339
std::optional< ProtocolCraft::Chat > GetDataCustomName() const
Definition Entity.cpp:814
virtual bool IsBoat() const
Definition Entity.cpp:1528
void LoadMetadataFromRawArray(const std::vector< unsigned char > &data)
Definition Entity.cpp:383
virtual bool IsRaft() const
Definition Entity.cpp:1543
virtual bool IsShoulderRidingEntity() const
Definition Entity.cpp:1423
float GetPitch() const
Definition Entity.cpp:956
void RemoveEffect(const EntityEffectType type)
Definition Entity.cpp:1220
virtual void SetPosition(const Vector3< double > &position_)
Definition Entity.cpp:1053
void SetDataTicksFrozen(const int data_ticks_frozen)
Definition Entity.cpp:907
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
EquipmentSlot
Definition Enums.hpp:285
EntityEffectType
Definition Enums.hpp:330
EntitySharedFlagsId
Definition Entity.hpp:43
std::array< unsigned char, 16 > UUID
std::chrono::steady_clock::time_point end
Definition Entity.hpp:39
unsigned char amplifier
Definition Entity.hpp:38
EntityEffectType type
Definition Entity.hpp:37