Botcraft 26.2
Loading...
Searching...
No Matches
Entity.cpp
Go to the documentation of this file.
2
6#if PROTOCOL_VERSION < 773 /* < 1.21.9 */
8#endif
9#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
11#endif
12#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
14#endif
15#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
17#endif
18
19#if USE_GUI
22#endif
24
25#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
27#endif
29#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
31#endif
34#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
36#endif
37#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
40#endif
42#if PROTOCOL_VERSION > 498 /* > 1.14.4 */
44#endif
47#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
49#endif
50#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
52#endif
53#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
55#endif
56#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
58#endif
59#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
61#endif
62#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
64#endif
65#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
67#endif
70#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
72#endif
73#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
75#endif
77#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
79#endif
80#if PROTOCOL_VERSION > 767 /* > 1.21.1 */ && PROTOCOL_VERSION < 769 /* < 1.21.4 */
82#endif
84#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
86#endif
89#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
91#endif
92#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
97#endif
109#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
111#endif
112#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
114#endif
116#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
118#endif
120#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
124#endif
126#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
128#endif
132#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
134#endif
138#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
140#endif
147#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
149#endif
150#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
152#endif
164#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
166#endif
168#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
170#endif
172#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
174#else
176#endif
177#if PROTOCOL_VERSION > 736 /* > 1.16.1 */
179#endif
180#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
182#endif
184#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
187#endif
189#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
191#endif
193#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
195#endif
196#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
198#endif
207#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
209#endif
216#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
218#endif
219#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
221#endif
225#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
227#endif
228#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
230#endif
231#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
233#endif
234
235#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
237#endif
238#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
240#endif
244#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
246#endif
247#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
249#endif
250#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
252#endif
258#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
260#endif
264#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
266#endif
269#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
273#endif
274#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
276#endif
277
278#include <mutex>
279
280namespace Botcraft
281{
282 const std::array<std::string, Entity::metadata_count> Entity::metadata_names{ {
283 "data_shared_flags_id",
284 "data_air_supply_id",
285 "data_custom_name",
286 "data_custom_name_visible",
287 "data_silent",
288 "data_no_gravity",
289#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
290 "data_pose",
291#endif
292#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
293 "data_ticks_frozen",
294#endif
295 } };
296
298 {
299 {
300 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
301 // Initialize base stuff
302 entity_id = 0;
303 position = Vector3<double>(0.0, 0.0, 0.0);
304 yaw = 0.0f;
305 pitch = 0.0f;
306 speed = Vector3<double>(0.0, 0.0, 0.0);
307 on_ground = false;
308 equipments = {
315#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
317#endif
318#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
320#endif
321 };
322 }
323
324 // Initialize all metadata with default values
327#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
328 SetDataCustomName(std::optional<ProtocolCraft::Chat>());
329#else
331#endif
333 SetDataSilent(false);
334 SetDataNoGravity(false);
335#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
337#endif
338#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
340#endif
341 }
342
344 {
345
346 }
347
348
350 {
351 std::shared_lock<std::shared_mutex> lock(entity_mutex);
352 return GetColliderImpl();
353 }
354
355 double Entity::GetWidth() const
356 {
357 std::shared_lock<std::shared_mutex> lock(entity_mutex);
358 return GetWidthImpl();
359 }
360
361 double Entity::GetHeight() const
362 {
363 std::shared_lock<std::shared_mutex> lock(entity_mutex);
364 return GetHeightImpl();
365 }
366
367
368 void Entity::LoadMetadataFromRawArray(const std::vector<unsigned char>& data)
369 {
370 if (data.size() == 0)
371 {
372 return;
373 }
374
375 ProtocolCraft::ReadIterator iter = data.begin();
376 size_t length = data.size();
377
378 while (true)
379 {
380 const unsigned char index = ProtocolCraft::ReadData<unsigned char>(iter, length);
381 if (index == 0xFF)
382 {
383 break;
384 }
385
386 const int type = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length);
387 std::any value;
388
389 enum EntityMetadataTypes
390 {
391 Char = 0,
392 Int,
393#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
394 Long,
395#endif
396 Float,
397 String,
398 Chat,
399#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
400 OptionalChat,
401#endif
402 Slot,
403 Bool,
404 Rotations,
405 BlockPosition,
406 OptionalBlockPosition,
407 DirectionType,
408#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
409 OptionalLivingEntityReference, // Fancy new name for 1.21.5, but it's still an optional UUID
410#else
411 OptionalUUID,
412#endif
413 BlockstateType,
414#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
415 OptionalBlockstate,
416#endif
417#if PROTOCOL_VERSION < 773 /* < 1.21.9 */
418 NBT,
419#endif
420#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
421 Particle,
422#endif
423#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
424 Particles,
425#endif
426#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
427 VillagerDataType,
428 OptionalUint,
429 PoseType,
430#endif
431#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
432 CatVariant,
433#endif
434#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
435 CatSoundVariant,
436#endif
437#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
438 CowVariant,
439#endif
440#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
441 CowSoundVariant,
442#endif
443#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
444 WolfVariant,
445#endif
446#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
447 WolfSoundVariant,
448#endif
449#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
450 FrogVariant,
451#endif
452#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
453 PigVariant,
454#endif
455#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
456 PigSoundVariant,
457#endif
458#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
459 ChickenVariant,
460#endif
461#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
462 ChickenSoundVariant,
463#endif
464#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
465 ZombieNautilusVariant,
466#endif
467#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
468 OptionalGlobalPos,
469 PaintingVariant,
470#endif
471#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
472 SnifferState,
473#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
474 ArmadilloState,
475#endif
476#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
477 CopperGolemState,
478 WeatheringCopperState,
479#endif
480 Vec3,
481 Quaternion,
482#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
483 ResolvableProfile,
484#endif
485#endif
486#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
487 HumanoidArm,
488#endif
489 };
490
491 switch (type)
492 {
493 case EntityMetadataTypes::Char:
494 value = ProtocolCraft::ReadData<char>(iter, length);
495 break;
496 case EntityMetadataTypes::Int:
497 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
498 break;
499#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
500 case EntityMetadataTypes::Long:
501 value = static_cast<long long int>(ProtocolCraft::ReadData<ProtocolCraft::VarLong>(iter, length));
502 break;
503#endif
504 case EntityMetadataTypes::Float:
505 value = ProtocolCraft::ReadData<float>(iter, length);
506 break;
507 case EntityMetadataTypes::String:
508 value = ProtocolCraft::ReadData<std::string>(iter, length);
509 break;
510 case EntityMetadataTypes::Chat:
511 value = ProtocolCraft::Chat();
512 std::any_cast<ProtocolCraft::Chat&>(value).Read(iter, length);
513 break;
514#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
515 case EntityMetadataTypes::OptionalChat:
516 if (ProtocolCraft::ReadData<bool>(iter, length))
517 {
518 value = std::optional<ProtocolCraft::Chat>(ProtocolCraft::Chat());
519 std::any_cast<std::optional<ProtocolCraft::Chat>&>(value).value().Read(iter, length);
520 }
521 else
522 {
523 value = std::optional<ProtocolCraft::Chat>();
524 }
525 break;
526#endif
527 case EntityMetadataTypes::Slot:
528 value = ProtocolCraft::Slot();
529 std::any_cast<ProtocolCraft::Slot&>(value).Read(iter, length);
530 break;
531 case EntityMetadataTypes::Bool:
532 value = ProtocolCraft::ReadData<bool>(iter, length);
533 break;
534 case EntityMetadataTypes::Rotations:
535 {
536 Vector3<float> rotation;
537 for (int i = 0; i < 3; ++i)
538 {
539 rotation[i] = ProtocolCraft::ReadData<float>(iter, length);
540 }
541 value = rotation;
542 break;
543 }
544 case EntityMetadataTypes::BlockPosition:
545 {
547 position.Read(iter, length);
548 value = Position(position);
549 break;
550 }
551 case EntityMetadataTypes::OptionalBlockPosition:
552 if (ProtocolCraft::ReadData<bool>(iter, length))
553 {
555 position.Read(iter, length);
556 value = std::optional<Position>(position);
557 }
558 else
559 {
560 value = std::optional<Position>();
561 }
562 break;
563 case EntityMetadataTypes::DirectionType:
564 value = static_cast<Direction>(static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length)));
565 break;
566#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
567 case EntityMetadataTypes::OptionalLivingEntityReference:
568#else
569 case EntityMetadataTypes::OptionalUUID:
570#endif
571 if (ProtocolCraft::ReadData<bool>(iter, length))
572 {
573 value = std::optional<ProtocolCraft::UUID>(ProtocolCraft::ReadData<ProtocolCraft::UUID>(iter, length));
574 }
575 else
576 {
577 value = std::optional<ProtocolCraft::UUID>();
578 }
579 break;
580 case EntityMetadataTypes::BlockstateType:
581 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
582 break;
583#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
584 case EntityMetadataTypes::OptionalBlockstate:
585 if (const int n = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length))
586 {
587 value = std::optional<int>(n);
588 }
589 else
590 {
591 value = std::optional<int>();
592 }
593 break;
594#endif
595#if PROTOCOL_VERSION < 773 /* < 1.21.9 */
596 case EntityMetadataTypes::NBT:
597 {
599 unnamed_value.Read(iter, length);
600 value = ProtocolCraft::NBT::Value(unnamed_value);
601 break;
602 }
603#endif
604#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
605 case EntityMetadataTypes::Particle:
606 {
608 particle.Read(iter, length);
609 value = particle;
610 break;
611 }
612#endif
613#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
614 case EntityMetadataTypes::Particles:
615 value = ProtocolCraft::ReadData<std::vector<ProtocolCraft::Particle>>(iter, length);
616 break;
617#endif
618#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
619 case EntityMetadataTypes::VillagerDataType:
620 value = VillagerData{
621 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length), // villager_type
622 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length), // villager_profession
623 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length) // level
624 };
625 break;
626 case EntityMetadataTypes::OptionalUint:
627 {
628 const int val = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length);
629 value = val > 0 ? std::optional<int>(val - 1) : std::optional<int>();
630 break;
631 }
632 case EntityMetadataTypes::PoseType:
633 value = static_cast<Pose>(static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length)));
634 break;
635#endif
636#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
637 case EntityMetadataTypes::CatVariant:
638 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
639 break;
640#endif
641#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
642 case EntityMetadataTypes::CatSoundVariant:
643 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
644 break;
645#endif
646#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
647 case EntityMetadataTypes::CowVariant:
648 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
649 break;
650#endif
651#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
652 case EntityMetadataTypes::CowSoundVariant:
653 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
654 break;
655#endif
656#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
657 case EntityMetadataTypes::WolfVariant:
658 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
659 break;
660#endif
661#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
662 case EntityMetadataTypes::WolfSoundVariant:
663 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
664 break;
665#endif
666#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
667 case EntityMetadataTypes::FrogVariant:
668 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
669 break;
670#endif
671#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
672 case EntityMetadataTypes::PigVariant:
673 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
674 break;
675#endif
676#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
677 case EntityMetadataTypes::PigSoundVariant:
678 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
679 break;
680#endif
681#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
682 case EntityMetadataTypes::ChickenVariant:
683 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
684 break;
685#endif
686#if PROTOCOL_VERSION > 774 /* > 1.21.11 */
687 case EntityMetadataTypes::ChickenSoundVariant:
688 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
689 break;
690#endif
691#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
692 case EntityMetadataTypes::ZombieNautilusVariant:
693 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
694 break;
695#endif
696#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
697 case EntityMetadataTypes::OptionalGlobalPos:
698 if (ProtocolCraft::ReadData<bool>(iter, length))
699 {
701 dimension.Read(iter, length);
703 pos.Read(iter, length);
704
705 value = std::optional<GlobalPos>({
706 dimension,
707 pos
708 });
709 }
710 else
711 {
712 value = std::optional<GlobalPos>();
713 }
714 break;
715 case EntityMetadataTypes::PaintingVariant:
716 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
717 break;
718#endif
719#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
720 case EntityMetadataTypes::SnifferState:
721 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
722 break;
723#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
724 case EntityMetadataTypes::ArmadilloState:
725 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
726 break;
727#endif
728#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
729 case EntityMetadataTypes::CopperGolemState:
730 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
731 break;
732 case EntityMetadataTypes::WeatheringCopperState:
733 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
734 break;
735#endif
736 case EntityMetadataTypes::Vec3:
737 {
738 const float x = ProtocolCraft::ReadData<float>(iter, length);
739 const float y = ProtocolCraft::ReadData<float>(iter, length);
740 const float z = ProtocolCraft::ReadData<float>(iter, length);
741 value = Vector3<float>(x, y, z);
742 }
743 break;
744 case EntityMetadataTypes::Quaternion:
745 {
746 const float x = ProtocolCraft::ReadData<float>(iter, length);
747 const float y = ProtocolCraft::ReadData<float>(iter, length);
748 const float z = ProtocolCraft::ReadData<float>(iter, length);
749 const float w = ProtocolCraft::ReadData<float>(iter, length);
750 value = std::array<float, 4>{x, y, z, w};
751 }
752 break;
753#endif
754#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
755 case EntityMetadataTypes::ResolvableProfile:
756 value = ProtocolCraft::ReadData<ProtocolCraft::Components::DataComponentTypeResolvableProfile>(iter, length);
757 break;
758#endif
759#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
760 case EntityMetadataTypes::HumanoidArm:
761 value = static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
762 break;
763#endif
764 default:
765 LOG_ERROR("Unknown type in entity metadata : " << type << ".Stopping current metadata parsing.");
766 return;
767 }
768 SetMetadataValue(index, value);
769 }
770 }
771
772 void Entity::SetMetadataValue(const int index, const std::any& value)
773 {
774 assert(index >= 0 && index < metadata_count);
775 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
776 const std::string& metadata_name = metadata_names[index];
777 metadata[metadata_name] = value;
778#if USE_GUI && PROTOCOL_VERSION > 404 /* > 1.13.2 */
779 if (metadata_name == "data_pose")
780 {
782 }
783#endif
784 }
785
786
788 {
789 std::shared_lock<std::shared_mutex> lock(entity_mutex);
791 }
792
794 {
795 std::shared_lock<std::shared_mutex> lock(entity_mutex);
796 return GetDataSharedFlagsIdImpl(id);
797 }
798
800 {
801 std::shared_lock<std::shared_mutex> lock(entity_mutex);
802 return std::any_cast<int>(metadata.at("data_air_supply_id"));
803 }
804
805#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
806 std::optional<ProtocolCraft::Chat> Entity::GetDataCustomName() const
807 {
808 std::shared_lock<std::shared_mutex> lock(entity_mutex);
809 return std::any_cast<std::optional<ProtocolCraft::Chat>>(metadata.at("data_custom_name"));
810 }
811#else
812 std::string Entity::GetDataCustomName() const
813 {
814 std::shared_lock<std::shared_mutex> lock(entity_mutex);
815 return std::any_cast<std::string>(metadata.at("data_custom_name"));
816 }
817#endif
818
820 {
821 std::shared_lock<std::shared_mutex> lock(entity_mutex);
822 return std::any_cast<bool>(metadata.at("data_custom_name_visible"));
823 }
824
826 {
827 std::shared_lock<std::shared_mutex> lock(entity_mutex);
828 return std::any_cast<bool>(metadata.at("data_silent"));
829 }
830
832 {
833 std::shared_lock<std::shared_mutex> lock(entity_mutex);
834 return std::any_cast<bool>(metadata.at("data_no_gravity"));
835 }
836
837#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
839 {
840 std::shared_lock<std::shared_mutex> lock(entity_mutex);
841 return GetDataPoseImpl();
842 }
843#endif
844
845#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
847 {
848 std::shared_lock<std::shared_mutex> lock(entity_mutex);
849 return std::any_cast<int>(metadata.at("data_ticks_frozen"));
850 }
851#endif
852
853
854 void Entity::SetDataSharedFlagsId(const char data_shared_flags_id)
855 {
856 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
857 SetDataSharedFlagsIdImpl(data_shared_flags_id);
858 }
859
861 {
862 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
864 }
865
866 void Entity::SetDataAirSupplyId(const int data_air_supply_id)
867 {
868 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
869 metadata["data_air_supply_id"] = data_air_supply_id;
870 }
871
872#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
873 void Entity::SetDataCustomName(const std::optional<ProtocolCraft::Chat>& data_custom_name)
874 {
875 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
876 metadata["data_custom_name"] = data_custom_name;
877 }
878#else
879 void Entity::SetDataCustomName(const std::string& data_custom_name)
880 {
881 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
882 metadata["data_custom_name"] = data_custom_name;
883 }
884#endif
885
886 void Entity::SetDataCustomNameVisible(const bool data_custom_name_visible)
887 {
888 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
889 metadata["data_custom_name_visible"] = data_custom_name_visible;
890 }
891
892 void Entity::SetDataSilent(const bool data_silent)
893 {
894 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
895 metadata["data_silent"] = data_silent;
896 }
897
898 void Entity::SetDataNoGravity(const bool data_no_gravity)
899 {
900 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
901 metadata["data_no_gravity"] = data_no_gravity;
902 }
903
904#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
905 void Entity::SetDataPose(const Pose data_pose)
906 {
907 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
908 SetDataPoseImpl(data_pose);
909 }
910#endif
911
912#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
913 void Entity::SetDataTicksFrozen(const int data_ticks_frozen)
914 {
915 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
916 metadata["data_ticks_frozen"] = data_ticks_frozen;
917 }
918#endif
919
920
922 {
923 std::shared_lock<std::shared_mutex> lock(entity_mutex);
924 return entity_id;
925 }
926
928 {
929 std::shared_lock<std::shared_mutex> lock(entity_mutex);
930 return uuid;
931 }
932
934 {
935 std::shared_lock<std::shared_mutex> lock(entity_mutex);
936 return position;
937 }
938
939 double Entity::GetX() const
940 {
941 std::shared_lock<std::shared_mutex> lock(entity_mutex);
942 return position.x;
943 }
944
945 double Entity::GetY() const
946 {
947 std::shared_lock<std::shared_mutex> lock(entity_mutex);
948 return position.y;
949 }
950
951 double Entity::GetZ() const
952 {
953 std::shared_lock<std::shared_mutex> lock(entity_mutex);
954 return position.z;
955 }
956
957 float Entity::GetYaw() const
958 {
959 std::shared_lock<std::shared_mutex> lock(entity_mutex);
960 return yaw;
961 }
962
963 float Entity::GetPitch() const
964 {
965 std::shared_lock<std::shared_mutex> lock(entity_mutex);
966 return pitch;
967 }
968
970 {
971 std::shared_lock<std::shared_mutex> lock(entity_mutex);
972 return speed;
973 }
974
975 double Entity::GetSpeedX() const
976 {
977 std::shared_lock<std::shared_mutex> lock(entity_mutex);
978 return speed.x;
979 }
980
981 double Entity::GetSpeedY() const
982 {
983 std::shared_lock<std::shared_mutex> lock(entity_mutex);
984 return speed.y;
985 }
986
987 double Entity::GetSpeedZ() const
988 {
989 std::shared_lock<std::shared_mutex> lock(entity_mutex);
990 return speed.z;
991 }
992
994 {
995 std::shared_lock<std::shared_mutex> lock(entity_mutex);
996 return on_ground;
997 }
998
999 std::map<EquipmentSlot, ProtocolCraft::Slot> Entity::GetEquipments() const
1000 {
1001 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1002 return equipments;
1003 }
1004
1006 {
1007 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1008 return equipments.at(slot);
1009 }
1010
1011 std::vector<EntityEffect> Entity::GetEffects() const
1012 {
1013 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1014 return effects;
1015 }
1016
1017#if USE_GUI
1018 std::vector<Renderer::Face> Entity::GetFaces(const bool reset_uptodate_status)
1019 {
1020 if (faces.size() == 0)
1021 {
1023 }
1024 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1026 {
1027 for (size_t i = 0; i < faces.size(); ++i)
1028 {
1029 faces[i].UpdateMatrix(face_descriptors[i].transformations, face_descriptors[i].orientation);
1030 }
1031 }
1032 if (reset_uptodate_status)
1033 {
1035 }
1036 return faces;
1037 }
1038
1040 {
1041 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1043 }
1044#endif
1045
1046
1047 void Entity::SetEntityID(const int entity_id_)
1048 {
1049 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1050 entity_id = entity_id_;
1051 }
1052
1054 {
1055 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1056 uuid = uuid_;
1057 }
1058
1060 {
1061 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1062#if USE_GUI
1063 if (position_ != position)
1064 {
1066 for (size_t i = 0; i < faces.size(); ++i)
1067 {
1068 std::shared_ptr<Renderer::Translation> f = std::static_pointer_cast<Renderer::Translation>(face_descriptors[i].transformations.translations.back());
1069 f->x = static_cast<float>(position_.x);
1070 f->y = static_cast<float>(position_.y);
1071 f->z = static_cast<float>(position_.z);
1072 }
1073 }
1074#endif
1075 position = position_;
1076 }
1077
1078 void Entity::SetX(const double x_)
1079 {
1080 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1081#if USE_GUI
1082 if (x_ != position.x)
1083 {
1085 for (size_t i = 0; i < faces.size(); ++i)
1086 {
1087 std::static_pointer_cast<Renderer::Translation>(face_descriptors[i].transformations.translations.back())->x = static_cast<float>(x_);
1088 }
1089 }
1090#endif
1091 position.x = x_;
1092 }
1093
1094 void Entity::SetY(const double y_)
1095 {
1096 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1097#if USE_GUI
1098 if (y_ != position.y)
1099 {
1101 for (size_t i = 0; i < faces.size(); ++i)
1102 {
1103 std::static_pointer_cast<Renderer::Translation>(face_descriptors[i].transformations.translations.back())->y = static_cast<float>(y_);
1104 }
1105 }
1106#endif
1107 position.y = y_;
1108 }
1109
1110 void Entity::SetZ(const double z_)
1111 {
1112 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1113#if USE_GUI
1114 if (z_ != position.z)
1115 {
1117 for (size_t i = 0; i < faces.size(); ++i)
1118 {
1119 std::static_pointer_cast<Renderer::Translation>(face_descriptors[i].transformations.translations.back())->z = static_cast<float>(z_);
1120 }
1121 }
1122#endif
1123 position.z = z_;
1124 }
1125
1126 void Entity::SetYaw(const float yaw_)
1127 {
1128 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1129#if USE_GUI
1130 if (yaw_ != yaw)
1131 {
1133 for (size_t i = 0; i < faces.size(); ++i)
1134 {
1135 std::static_pointer_cast<Renderer::Rotation>(face_descriptors[i].transformations.rotations.front())->deg_angle = yaw_;
1136 }
1137 }
1138#endif
1139 yaw = yaw_;
1140 }
1141
1142 void Entity::SetPitch(const float pitch_)
1143 {
1144 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1145#if USE_GUI
1146 if (pitch_ != pitch)
1147 {
1149 for (size_t i = 0; i < faces.size(); ++i)
1150 {
1151 std::static_pointer_cast<Renderer::Rotation>(face_descriptors[i].transformations.rotations.back())->deg_angle = pitch_;
1152 }
1153 }
1154#endif
1155 pitch = pitch_;
1156 }
1157
1159 {
1160 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1161 speed = speed_;
1162 }
1163
1164 void Entity::SetSpeedX(const double speed_x_)
1165 {
1166 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1167 speed.x = speed_x_;
1168 }
1169
1170 void Entity::SetSpeedY(const double speed_y_)
1171 {
1172 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1173 speed.y = speed_y_;
1174 }
1175
1176 void Entity::SetSpeedZ(const double speed_z_)
1177 {
1178 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1179 speed.z = speed_z_;
1180 }
1181
1182 void Entity::SetOnGround(const bool on_ground_)
1183 {
1184 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1185 on_ground = on_ground_;
1186 }
1187
1189 {
1190 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1191 equipments.at(slot) = item;
1192 }
1193
1194 void Entity::SetEffects(const std::vector<EntityEffect>& effects_)
1195 {
1196 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1197 effects = effects_;
1198 }
1199
1201 {
1202 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1203 for (auto it = effects.begin(); it != effects.end();)
1204 {
1205 if (it->type == type)
1206 {
1207 it = effects.erase(it);
1208 }
1209 else
1210 {
1211 ++it;
1212 }
1213 }
1214 }
1215
1217 {
1218 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1219 // First, remove any instance of this type of effect on the entity
1220 for (auto it = effects.begin(); it != effects.end();)
1221 {
1222 if (it->type == effect.type)
1223 {
1224 it = effects.erase(it);
1225 }
1226 else
1227 {
1228 ++it;
1229 }
1230 }
1231
1232 // Then add the new one
1233 effects.push_back(effect);
1234 }
1235
1236#if USE_GUI
1237 void Entity::SetAreRenderedFacesUpToDate(const bool should_be_updated_)
1238 {
1239 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
1240 are_rendered_faces_up_to_date = should_be_updated_;
1241 }
1242#endif
1243
1244
1246 {
1248
1249 {
1250 std::shared_lock<std::shared_mutex> lock(entity_mutex);
1251 output["id"] = entity_id;
1252 output["position"] = position.Serialize();
1253 output["yaw"] = yaw;
1254 output["pitch"] = pitch;
1255 output["speed"] = speed.Serialize();
1256 output["on_ground"] = on_ground;
1257 output["equipment"] = ProtocolCraft::Json::Value();
1258 for (auto& p : equipments)
1259 {
1260 output["equipment"][std::to_string(static_cast<int>(p.first))] = p.second.Serialize();
1261 }
1262 }
1263
1264 output["metadata"] = ProtocolCraft::Json::Value();
1265
1266 output["metadata"]["data_shared_flags_id"] = GetDataSharedFlagsId();
1267 output["metadata"]["data_air_supply_id"] = GetDataAirSupplyId();
1268#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1269 output["metadata"]["data_custom_name"] = GetDataCustomName() ? GetDataCustomName().value().Serialize() : ProtocolCraft::Json::Value();
1270#else
1271 output["metadata"]["data_custom_name"] = GetDataCustomName();
1272#endif
1273 output["metadata"]["data_custom_name_visible"] = GetDataCustomNameVisible();
1274 output["metadata"]["data_silent"] = GetDataSilent();
1275 output["metadata"]["data_no_gravity"] = GetDataNoGravity();
1276#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1277 output["metadata"]["data_pose"] = static_cast<int>(GetDataPose());
1278#endif
1279#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
1280 output["metadata"]["data_ticks_frozen"] = GetDataTicksFrozen();
1281#endif
1282
1283 return output;
1284 }
1285
1287 {
1288 return false;
1289 }
1290
1292 {
1293 return false;
1294 }
1295
1297 {
1298 return false;
1299 }
1300
1302 {
1303 return false;
1304 }
1305
1306 bool Entity::IsAnimal() const
1307 {
1308 return false;
1309 }
1310
1312 {
1313 return false;
1314 }
1315
1317 {
1318 return false;
1319 }
1320
1321#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
1323 {
1324 return false;
1325 }
1326#endif
1327
1328#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
1330 {
1331 return false;
1332 }
1333#endif
1334
1336 {
1337 return false;
1338 }
1339
1341 {
1342 return false;
1343 }
1344
1346 {
1347 return false;
1348 }
1349
1351 {
1352 return false;
1353 }
1354
1356 {
1357 return false;
1358 }
1359
1360 bool Entity::IsMob() const
1361 {
1362 return false;
1363 }
1364
1366 {
1367 return false;
1368 }
1369
1370#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1372 {
1373 return false;
1374 }
1375#endif
1376
1377#if PROTOCOL_VERSION < 771 /* < 1.21.6 */
1378 bool Entity::IsFlyingMob() const
1379 {
1380 return false;
1381 }
1382#endif
1383
1385 {
1386 return false;
1387 }
1388
1390 {
1391 return false;
1392 }
1393
1395 {
1396 return false;
1397 }
1398
1400 {
1401 return false;
1402 }
1403
1405 {
1406 return false;
1407 }
1408
1409#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
1411 {
1412 return false;
1413 }
1414#endif
1415
1417 {
1418 return false;
1419 }
1420
1422 {
1423 return false;
1424 }
1425
1426#if PROTOCOL_VERSION > 736 /* > 1.16.1 */
1428 {
1429 return false;
1430 }
1431#endif
1432
1434 {
1435 return false;
1436 }
1437
1438#if PROTOCOL_VERSION > 769 /* > 1.21.4 */
1440 {
1441 return false;
1442 }
1443#endif
1444
1446 {
1447 return false;
1448 }
1449
1450#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1451 bool Entity::IsRaider() const
1452 {
1453 return false;
1454 }
1455#endif
1456
1458 {
1459 return false;
1460 }
1461
1463 {
1464 return false;
1465 }
1466
1467#if PROTOCOL_VERSION > 477 /* > 1.14 */
1469 {
1470 return false;
1471 }
1472#endif
1473
1475 {
1476 return false;
1477 }
1478
1480 {
1481 return false;
1482 }
1483
1484#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1486 {
1487 return false;
1488 }
1489#endif
1490
1492 {
1493 return false;
1494 }
1495
1496#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
1498 {
1499 return false;
1500 }
1501#endif
1502
1503#if PROTOCOL_VERSION > 766 /* > 1.20.6 */
1505 {
1506 return false;
1507 }
1508#endif
1509
1510#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
1512 {
1513 return false;
1514 }
1515
1517 {
1518 return false;
1519 }
1520
1522 {
1523 return false;
1524 }
1525
1526 bool Entity::IsBoat() const
1527 {
1528 return false;
1529 }
1530
1532 {
1533 return false;
1534 }
1535
1537 {
1538 return false;
1539 }
1540
1541 bool Entity::IsRaft() const
1542 {
1543 return false;
1544 }
1545#endif
1546
1547#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
1548 bool Entity::IsAvatar() const
1549 {
1550 return false;
1551 }
1552#endif
1553
1554#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
1556 {
1557 return false;
1558 }
1559#endif
1560
1561#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
1563 {
1564 return false;
1565 }
1566#endif
1567
1568
1569 std::shared_ptr<Entity> Entity::CreateEntity(const EntityType type)
1570 {
1571 switch (type)
1572 {
1573 case EntityType::None:
1574 return nullptr;
1575#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
1576 case EntityType::Allay:
1577 return std::make_shared<AllayEntity>();
1578#endif
1580 return std::make_shared<AreaEffectCloudEntity>();
1581#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
1583 return std::make_shared<ArmadilloEntity>();
1584#endif
1586 return std::make_shared<ArmorStandEntity>();
1587 case EntityType::Arrow:
1588 return std::make_shared<ArrowEntity>();
1589#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
1591 return std::make_shared<AxolotlEntity>();
1592#endif
1593 case EntityType::Bat:
1594 return std::make_shared<BatEntity>();
1595#if PROTOCOL_VERSION > 498 /* > 1.14.4 */
1596 case EntityType::Bee:
1597 return std::make_shared<BeeEntity>();
1598#endif
1599 case EntityType::Blaze:
1600 return std::make_shared<BlazeEntity>();
1601#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
1602 case EntityType::Boat:
1603 return std::make_shared<BoatEntity>();
1604#else
1614 return std::make_shared<BoatEntity>(type);
1615#endif
1616#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
1617 case EntityType::Bogged:
1618 return std::make_shared<BoggedEntity>();
1619#endif
1620#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
1621 case EntityType::Breeze:
1622 return std::make_shared<BreezeEntity>();
1623#endif
1624#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
1626 return std::make_shared<BreezeWindChargeEntity>();
1627#endif
1628#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
1629#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
1630 case EntityType::ChestBoat:
1631 return std::make_shared<ChestBoatEntity>();
1632#else
1642 return std::make_shared<ChestBoatEntity>(type);
1643#endif
1644#endif
1645#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
1647 return std::make_shared<ChestRaftEntity>(type);
1648#endif
1649#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1650 case EntityType::Cat:
1651 return std::make_shared<CatEntity>();
1652#endif
1653#if PROTOCOL_VERSION > 760 /* > 1.19.2 */
1654 case EntityType::Camel:
1655 return std::make_shared<CamelEntity>();
1656#endif
1657#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
1659 return std::make_shared<CamelHuskEntity>();
1660#endif
1662 return std::make_shared<CaveSpiderEntity>();
1664 return std::make_shared<ChickenEntity>();
1665#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1666 case EntityType::Cod:
1667 return std::make_shared<CodEntity>();
1668#endif
1669#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
1671 return std::make_shared<CopperGolemEntity>();
1672#endif
1673 case EntityType::Cow:
1674 return std::make_shared<CowEntity>();
1675#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
1677 return std::make_shared<CreakingEntity>();
1678#endif
1679#if PROTOCOL_VERSION > 767 /* > 1.21.1 */ && PROTOCOL_VERSION < 769 /* < 1.21.4 */
1680 case EntityType::CreakingTransient:
1681 return std::make_shared<CreakingTransientEntity>();
1682#endif
1684 return std::make_shared<CreeperEntity>();
1685#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
1687 return std::make_shared<DisplayBlockDisplayEntity>();
1689 return std::make_shared<DisplayItemDisplayEntity>();
1691 return std::make_shared<DisplayTextDisplayEntity>();
1692#endif
1693#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1695 return std::make_shared<DolphinEntity>();
1696#endif
1697 case EntityType::Donkey:
1698 return std::make_shared<DonkeyEntity>();
1700 return std::make_shared<DragonFireballEntity>();
1701#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1703 return std::make_shared<DrownedEntity>();
1704#endif
1706 return std::make_shared<ElderGuardianEntity>();
1708 return std::make_shared<EndCrystalEntity>();
1710 return std::make_shared<EnderDragonEntity>();
1712 return std::make_shared<EnderManEntity>();
1714 return std::make_shared<EndermiteEntity>();
1715 case EntityType::Evoker:
1716 return std::make_shared<EvokerEntity>();
1718 return std::make_shared<EvokerFangsEntity>();
1720 return std::make_shared<ExperienceOrbEntity>();
1722 return std::make_shared<EyeOfEnderEntity>();
1724 return std::make_shared<FallingBlockEntity>();
1726 return std::make_shared<FireworkRocketEntity>();
1727#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1728 case EntityType::Fox:
1729 return std::make_shared<FoxEntity>();
1730#endif
1731#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
1732 case EntityType::Frog:
1733 return std::make_shared<FrogEntity>();
1734#endif
1735 case EntityType::Ghast:
1736 return std::make_shared<GhastEntity>();
1737#if PROTOCOL_VERSION > 770 /* > 1.21.5 */
1739 return std::make_shared<HappyGhastEntity>();
1740#endif
1741 case EntityType::Giant:
1742 return std::make_shared<GiantEntity>();
1743#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
1745 return std::make_shared<GlowItemFrameEntity>();
1747 return std::make_shared<GlowSquidEntity>();
1748 case EntityType::Goat:
1749 return std::make_shared<GoatEntity>();
1750#endif
1752 return std::make_shared<GuardianEntity>();
1753#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1754 case EntityType::Hoglin:
1755 return std::make_shared<HoglinEntity>();
1756#endif
1757 case EntityType::Horse:
1758 return std::make_shared<HorseEntity>();
1759 case EntityType::Husk:
1760 return std::make_shared<HuskEntity>();
1762 return std::make_shared<IllusionerEntity>();
1763#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
1765 return std::make_shared<InteractionEntity>();
1766#endif
1768 return std::make_shared<IronGolemEntity>();
1770 return std::make_shared<ItemEntity>();
1772 return std::make_shared<ItemFrameEntity>();
1773#if PROTOCOL_VERSION > 765 /* > 1.20.4 */
1775 return std::make_shared<OminousItemSpawnerEntity>();
1776#endif
1778 return std::make_shared<LargeFireballEntity>();
1780 return std::make_shared<LeashFenceKnotEntity>();
1781#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1783 return std::make_shared<LightningBoltEntity>();
1784#endif
1785 case EntityType::Llama:
1786 return std::make_shared<LlamaEntity>();
1788 return std::make_shared<LlamaSpitEntity>();
1790 return std::make_shared<MagmaCubeEntity>();
1791#if PROTOCOL_VERSION > 772 /* > 1.21.8 */
1793 return std::make_shared<MannequinEntity>();
1794#endif
1795#if PROTOCOL_VERSION > 754 /* > 1.16.5 */
1796 case EntityType::Marker:
1797 return std::make_shared<MarkerEntity>();
1798#endif
1800 return std::make_shared<MinecartEntity>();
1802 return std::make_shared<MinecartChestEntity>();
1804 return std::make_shared<MinecartCommandBlockEntity>();
1806 return std::make_shared<MinecartFurnaceEntity>();
1808 return std::make_shared<MinecartHopperEntity>();
1810 return std::make_shared<MinecartSpawnerEntity>();
1812 return std::make_shared<MinecartTNTEntity>();
1813 case EntityType::Mule:
1814 return std::make_shared<MuleEntity>();
1815#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
1817 return std::make_shared<NautilusEntity>();
1818#endif
1820 return std::make_shared<MushroomCowEntity>();
1821 case EntityType::Ocelot:
1822 return std::make_shared<OcelotEntity>();
1824 return std::make_shared<PaintingEntity>();
1825#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1826 case EntityType::Panda:
1827 return std::make_shared<PandaEntity>();
1828#endif
1829#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
1831 return std::make_shared<ParchedEntity>();
1832#endif
1833 case EntityType::Parrot:
1834 return std::make_shared<ParrotEntity>();
1835#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1837 return std::make_shared<PhantomEntity>();
1838#endif
1839 case EntityType::Pig:
1840 return std::make_shared<PigEntity>();
1841#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1842 case EntityType::Piglin:
1843 return std::make_shared<PiglinEntity>();
1844#endif
1845#if PROTOCOL_VERSION > 736 /* > 1.16.1 */
1847 return std::make_shared<PiglinBruteEntity>();
1848#endif
1849#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1851 return std::make_shared<PillagerEntity>();
1852#endif
1854 return std::make_shared<PolarBearEntity>();
1856 return std::make_shared<PrimedTntEntity>();
1857#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1859 return std::make_shared<PufferfishEntity>();
1860#endif
1861 case EntityType::Rabbit:
1862 return std::make_shared<RabbitEntity>();
1863#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
1864 case EntityType::Raft:
1865 return std::make_shared<RaftEntity>(type);
1866#endif
1867#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1869 return std::make_shared<RavagerEntity>();
1870#endif
1871#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1872 case EntityType::Salmon:
1873 return std::make_shared<SalmonEntity>();
1874#endif
1875 case EntityType::Sheep:
1876 return std::make_shared<SheepEntity>();
1878 return std::make_shared<ShulkerEntity>();
1880 return std::make_shared<ShulkerBulletEntity>();
1882 return std::make_shared<SilverfishEntity>();
1884 return std::make_shared<SkeletonEntity>();
1886 return std::make_shared<SkeletonHorseEntity>();
1887 case EntityType::Slime:
1888 return std::make_shared<SlimeEntity>();
1890 return std::make_shared<SmallFireballEntity>();
1891#if PROTOCOL_VERSION > 761 /* > 1.19.3 */
1893 return std::make_shared<SnifferEntity>();
1894#endif
1896 return std::make_shared<SnowGolemEntity>();
1898 return std::make_shared<SnowballEntity>();
1900 return std::make_shared<SpectralArrowEntity>();
1901 case EntityType::Spider:
1902 return std::make_shared<SpiderEntity>();
1903 case EntityType::Squid:
1904 return std::make_shared<SquidEntity>();
1905 case EntityType::Stray:
1906 return std::make_shared<StrayEntity>();
1907#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1909 return std::make_shared<StriderEntity>();
1910#endif
1911#if PROTOCOL_VERSION > 775 /* > 26.1.2 */
1913 return std::make_shared<SulfurCubeEntity>();
1914#endif
1915#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
1917 return std::make_shared<TadpoleEntity>();
1918#endif
1920 return std::make_shared<ThrownEggEntity>();
1922 return std::make_shared<ThrownEnderpearlEntity>();
1924 return std::make_shared<ThrownExperienceBottleEntity>();
1925#if PROTOCOL_VERSION < 770 /* < 1.21.5 */
1926 case EntityType::ThrownPotion:
1927 return std::make_shared<ThrownPotionEntity>();
1928#else
1930 return std::make_shared<ThrownSplashPotionEntity>();
1932 return std::make_shared<ThrownLingeringPotionEntity>();
1933#endif
1934#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1936 return std::make_shared<ThrownTridentEntity>();
1937#endif
1938#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1940 return std::make_shared<TraderLlamaEntity>();
1941#endif
1942#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1944 return std::make_shared<TropicalFishEntity>();
1945#endif
1946#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
1947 case EntityType::Turtle:
1948 return std::make_shared<TurtleEntity>();
1949#endif
1950 case EntityType::Vex:
1951 return std::make_shared<VexEntity>();
1953 return std::make_shared<VillagerEntity>();
1955 return std::make_shared<VindicatorEntity>();
1956#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
1958 return std::make_shared<WanderingTraderEntity>();
1959#endif
1960#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
1961 case EntityType::Warden:
1962 return std::make_shared<WardenEntity>();
1963#endif
1964#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
1966 return std::make_shared<WindChargeEntity>();
1967#endif
1968 case EntityType::Witch:
1969 return std::make_shared<WitchEntity>();
1971 return std::make_shared<WitherBossEntity>();
1973 return std::make_shared<WitherSkeletonEntity>();
1975 return std::make_shared<WitherSkullEntity>();
1976 case EntityType::Wolf:
1977 return std::make_shared<WolfEntity>();
1978#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1979 case EntityType::Zoglin:
1980 return std::make_shared<ZoglinEntity>();
1981#endif
1982 case EntityType::Zombie:
1983 return std::make_shared<ZombieEntity>();
1985 return std::make_shared<ZombieHorseEntity>();
1986#if PROTOCOL_VERSION > 773 /* > 1.21.10 */
1988 return std::make_shared<ZombieNautilusEntity>();
1989#endif
1991 return std::make_shared<ZombieVillagerEntity>();
1992#if PROTOCOL_VERSION > 578 /* > 1.15.2 */
1994 return std::make_shared<ZombifiedPiglinEntity>();
1995#else
1996 case EntityType::PigZombie:
1997 return std::make_shared<PigZombieEntity>();
1998#endif
1999 case EntityType::Player:
2000 return std::make_shared<PlayerEntity>();
2001#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
2003 return std::make_shared<FishingHookEntity>();
2004#endif
2005 default:
2006 return nullptr;
2007 }
2008 }
2009
2010#if PROTOCOL_VERSION < 458 /* < 1.14 */
2011 std::shared_ptr<Entity> Entity::CreateObjectEntity(const ObjectEntityType type)
2012 {
2013 switch (type)
2014 {
2015 case ObjectEntityType::None:
2016 return nullptr;
2017 case ObjectEntityType::Boat:
2018 return std::make_shared<BoatEntity>();
2019 case ObjectEntityType::ItemEntity:
2020 return std::make_shared<ItemEntity>();
2021 case ObjectEntityType::AreaEffectCloud:
2022 return std::make_shared<AreaEffectCloudEntity>();
2023 case ObjectEntityType::PrimedTnt:
2024 return std::make_shared<PrimedTntEntity>();
2025 case ObjectEntityType::EndCrystal:
2026 return std::make_shared<EndCrystalEntity>();
2027 case ObjectEntityType::Arrow:
2028 return std::make_shared<ArrowEntity>();
2029 case ObjectEntityType::Snowball:
2030 return std::make_shared<SnowballEntity>();
2031 case ObjectEntityType::ThrownEgg:
2032 return std::make_shared<ThrownEggEntity>();
2033 case ObjectEntityType::LargeFireball:
2034 return std::make_shared<LargeFireballEntity>();
2035 case ObjectEntityType::SmallFireball:
2036 return std::make_shared<SmallFireballEntity>();
2037 case ObjectEntityType::ThrownEnderpearl:
2038 return std::make_shared<ThrownEnderpearlEntity>();
2039 case ObjectEntityType::WitherSkull:
2040 return std::make_shared<WitherSkullEntity>();
2041 case ObjectEntityType::ShulkerBullet:
2042 return std::make_shared<ShulkerBulletEntity>();
2043 case ObjectEntityType::LlamaSpit:
2044 return std::make_shared<LlamaSpitEntity>();
2045 case ObjectEntityType::FallingBlockEntity:
2046 return std::make_shared<FallingBlockEntity>();
2047 case ObjectEntityType::ItemFrame:
2048 return std::make_shared<ItemFrameEntity>();
2049 case ObjectEntityType::EyeOfEnder:
2050 return std::make_shared<EyeOfEnderEntity>();
2051 case ObjectEntityType::ThrownPotion:
2052 return std::make_shared<ThrownPotionEntity>();
2053 case ObjectEntityType::ThrownExperienceBottle:
2054 return std::make_shared<ThrownExperienceBottleEntity>();
2055 case ObjectEntityType::FireworkRocketEntity:
2056 return std::make_shared<FireworkRocketEntity>();
2057 case ObjectEntityType::LeashFenceKnotEntity:
2058 return std::make_shared<LeashFenceKnotEntity>();
2059 case ObjectEntityType::ArmorStand:
2060 return std::make_shared<ArmorStandEntity>();
2061 case ObjectEntityType::EvokerFangs:
2062 return std::make_shared<EvokerFangsEntity>();
2063 case ObjectEntityType::FishingHook:
2064 return std::make_shared<FishingHookEntity>();
2065 case ObjectEntityType::SpectralArrow:
2066 return std::make_shared<SpectralArrowEntity>();
2067 case ObjectEntityType::DragonFireball:
2068 return std::make_shared<DragonFireballEntity>();
2069#if PROTOCOL_VERSION > 340 /* > 1.12.2 */
2070 case ObjectEntityType::ThrownTrident:
2071 return std::make_shared<ThrownTridentEntity>();
2072#endif
2073 default:
2074 return nullptr;
2075 }
2076 }
2077#endif
2078
2079#if USE_GUI
2081 {
2082 std::scoped_lock<std::shared_mutex> lock(entity_mutex);
2084
2085 // Generate default faces
2086 face_descriptors = std::vector<FaceDescriptor>(6);
2087 faces = std::vector<Renderer::Face>(6);
2088 const double half_height = GetHeightImpl() / 2.0;
2089 const double half_width = GetWidthImpl() / 2.0;
2090 for (int i = 0; i < 6; ++i)
2091 {
2092 face_descriptors[i].orientation = static_cast<Orientation>(i);
2093 face_descriptors[i].texture_names = { "" };
2094 face_descriptors[i].cullface_direction = Orientation::None;
2095 face_descriptors[i].use_tintindexes = { false };
2096
2097 // Base entity scale
2098 face_descriptors[i].transformations.scales.push_back(std::make_shared<Renderer::Scale>(
2099 static_cast<float>(half_width),
2100 static_cast<float>(half_height),
2101 static_cast<float>(half_width)
2102 ));
2103 // Base translation
2104 face_descriptors[i].transformations.translations.push_back(std::make_shared<Renderer::Translation>(0.0f, static_cast<float>(half_height), 0.0f));
2105 // Entity pos translation
2106 face_descriptors[i].transformations.translations.push_back(std::make_shared<Renderer::Translation>(
2107 static_cast<float>(position.x),
2108 static_cast<float>(position.y),
2109 static_cast<float>(position.z))
2110 );
2111 // Entity yaw/pitch rotation
2112 face_descriptors[i].transformations.rotations.push_back(std::make_shared<Renderer::Rotation>(0.0f, 1.0f, 0.0f, yaw));
2113 face_descriptors[i].transformations.rotations.push_back(std::make_shared<Renderer::Rotation>(1.0f, 0.0f, 0.0f, pitch));
2114
2115 face_descriptors[i].transformations.rotation = 0;
2116
2117 faces[i] = Renderer::Face(face_descriptors[i].transformations, face_descriptors[i].orientation);
2118 faces[i].SetDisplayBackface(false);
2119 faces[i].SetTextureMultipliers({ 0xFFFFFFFF, 0xFFFFFFFF });
2120
2121 // Extract texture info from the atlas
2122 std::array<unsigned short, 4> texture_pos = { 0, 0, 0, 0 };
2123 std::array<unsigned short, 4> texture_size = { 0, 0, 0, 0 };
2124 std::array<Renderer::Transparency, 2> transparencies = { Renderer::Transparency::Opaque, Renderer::Transparency::Opaque };
2125 std::array<Renderer::Animation, 2> animated = { Renderer::Animation::Static, Renderer::Animation::Static };
2126
2127 for (int j = 0; j < std::min(2, static_cast<int>(face_descriptors[i].texture_names.size())); ++j)
2128 {
2129 const Renderer::TextureData& texture_data = atlas->GetData(face_descriptors[i].texture_names[j]);
2130 std::tie(texture_pos[2 * j + 0], texture_pos[2 * j + 1]) = texture_data.position;
2131 std::tie(texture_size[2 * j + 0], texture_size[2 * j + 1]) = texture_data.size;
2132 transparencies[j] = texture_data.transparency;
2133 animated[j] = texture_data.animation;
2134 }
2135
2136 // Main texture coords in the atlas
2137 std::array<float, 4> coords = faces[i].GetTextureCoords(false);
2138 unsigned short height_normalizer = animated[0] == Renderer::Animation::Animated ? texture_size[0] : texture_size[1];
2139 coords[0] = (texture_pos[0] + coords[0] / 16.0f * texture_size[0]) / atlas->GetWidth();
2140 coords[1] = (texture_pos[1] + coords[1] / 16.0f * height_normalizer) / atlas->GetHeight();
2141 coords[2] = (texture_pos[0] + coords[2] / 16.0f * texture_size[0]) / atlas->GetWidth();
2142 coords[3] = (texture_pos[1] + coords[3] / 16.0f * height_normalizer) / atlas->GetHeight();
2143 faces[i].SetTextureCoords(coords, false);
2144
2145 // Overlay texture coords in the atlas if existing
2146 if (face_descriptors[i].texture_names.size() > 1)
2147 {
2148 coords = faces[i].GetTextureCoords(true);
2149 height_normalizer = animated[1] == Renderer::Animation::Animated ? texture_size[2] : texture_size[3];
2150 coords[0] = (texture_pos[2] + coords[0] / 16.0f * texture_size[2]) / atlas->GetWidth();
2151 coords[1] = (texture_pos[3] + coords[1] / 16.0f * height_normalizer) / atlas->GetHeight();
2152 coords[2] = (texture_pos[2] + coords[2] / 16.0f * texture_size[2]) / atlas->GetWidth();
2153 coords[3] = (texture_pos[3] + coords[3] / 16.0f * height_normalizer) / atlas->GetHeight();
2154 faces[i].SetTextureCoords(coords, true);
2155 }
2156
2157 faces[i].SetTransparencyData(transparencies[0]);
2158 }
2160 }
2161
2163 {
2165 const double half_width = GetWidthImpl() / 2.0;
2166 const double half_height = GetHeightImpl() / 2.0;
2167 for (size_t i = 0; i < faces.size(); ++i)
2168 {
2169 std::static_pointer_cast<Renderer::Scale>(face_descriptors[i].transformations.scales.back())->axis_x = static_cast<float>(half_width);
2170 std::static_pointer_cast<Renderer::Scale>(face_descriptors[i].transformations.scales.back())->axis_y = static_cast<float>(half_height);
2171 std::static_pointer_cast<Renderer::Scale>(face_descriptors[i].transformations.scales.back())->axis_z = static_cast<float>(half_width);
2172 std::static_pointer_cast<Renderer::Translation>(face_descriptors[i].transformations.translations.front())->y = static_cast<float>(half_height);
2173 }
2174 }
2175#endif
2176
2178 {
2179 return std::any_cast<char>(metadata.at("data_shared_flags_id"));
2180 }
2181
2183 {
2184 return (GetDataSharedFlagsIdImpl() >> static_cast<char>(id)) & 0x01;
2185 }
2186
2187 void Entity::SetDataSharedFlagsIdImpl(const char data_shared_flags_id)
2188 {
2189 metadata["data_shared_flags_id"] = data_shared_flags_id;
2190 }
2191
2193 {
2194 char current_value = GetDataSharedFlagsIdImpl();
2195 // Set the bit to 0
2196 const char mask = 0x01 << static_cast<char>(id);
2197 current_value &= ~mask;
2198 // Set the bit to b
2199 current_value |= b << static_cast<char>(id);
2200 SetDataSharedFlagsIdImpl(current_value);
2201 }
2202
2203#if PROTOCOL_VERSION > 404 /* > 1.13.2 */
2205 {
2206 return std::any_cast<Pose>(metadata.at("data_pose"));
2207 }
2208
2209 void Entity::SetDataPoseImpl(const Pose data_pose)
2210 {
2211 metadata["data_pose"] = data_pose;
2212#if USE_GUI
2213 OnSizeUpdated();
2214#endif
2215 }
2216#endif
2217
2219 {
2220 const double half_width = GetWidthImpl() / 2.0;
2221 const double half_height = GetHeightImpl() / 2.0;
2222 return AABB(Vector3<double>(position.x, position.y + half_height, position.z), Vector3<double>(half_width, half_height, half_width));
2223 }
2224
2226 {
2227 return -1.0;
2228 }
2229
2231 {
2232 return -1.0;
2233 }
2234}
#define LOG_ERROR(osstream)
Definition Logger.hpp:45
const Renderer::Atlas * GetAtlas() const
static AssetsManager & getInstance()
int GetDataTicksFrozen() const
Definition Entity.cpp:846
void OnSizeUpdated()
Definition Entity.cpp:2162
bool GetOnGround() const
Definition Entity.cpp:993
ProtocolCraft::UUID uuid
Definition Entity.hpp:273
virtual double GetHeightImpl() const
Definition Entity.cpp:2230
void SetDataSilent(const bool data_silent)
Definition Entity.cpp:892
virtual ProtocolCraft::Json::Value Serialize() const
Definition Entity.cpp:1245
void SetDataPose(const Pose data_pose)
Definition Entity.cpp:905
std::map< EquipmentSlot, ProtocolCraft::Slot > equipments
Items on this entity.
Definition Entity.hpp:282
virtual void SetY(const double y_)
Definition Entity.cpp:1094
double GetZ() const
Definition Entity.cpp:951
virtual bool IsAbstractChestedHorse() const
Definition Entity.cpp:1350
virtual bool IsWaterAnimal() const
Definition Entity.cpp:1345
void SetEffects(const std::vector< EntityEffect > &effects_)
Definition Entity.cpp:1194
void SetDataAirSupplyId(const int data_air_supply_id)
Definition Entity.cpp:866
void SetDataSharedFlagsIdImpl(const char data_shared_flags_id)
Definition Entity.cpp:2187
Vector3< double > GetSpeed() const
Definition Entity.cpp:969
void SetUUID(const ProtocolCraft::UUID &uuid_)
Definition Entity.cpp:1053
std::map< EquipmentSlot, ProtocolCraft::Slot > GetEquipments() const
Definition Entity.cpp:999
Vector3< double > speed
Definition Entity.hpp:277
virtual bool IsAbstractArrow() const
Definition Entity.cpp:1301
virtual bool IsAbstractSkeleton() const
Definition Entity.cpp:1457
virtual bool IsAbstractPiglin() const
Definition Entity.cpp:1427
int GetEntityID() const
Definition Entity.cpp:921
virtual bool IsLocalPlayer() const
Definition Entity.cpp:1286
double GetHeight() const
Definition Entity.cpp:361
std::vector< EntityEffect > effects
Definition Entity.hpp:283
char GetDataSharedFlagsIdImpl() const
Definition Entity.cpp:2177
virtual bool IsRemotePlayer() const
Definition Entity.cpp:1291
virtual bool IsAbstractNautilus() const
Definition Entity.cpp:1555
bool GetDataSilent() const
Definition Entity.cpp:825
void SetDataPoseImpl(const Pose data_pose)
Definition Entity.cpp:2209
double GetSpeedX() const
Definition Entity.cpp:975
virtual bool IsAbstractBoat() const
Definition Entity.cpp:1511
virtual bool IsAbstractHurtingProjectile() const
Definition Entity.cpp:1355
ProtocolCraft::UUID GetUUID() const
Definition Entity.cpp:927
double GetY() const
Definition Entity.cpp:945
virtual bool IsAbstractSchoolingFish() const
Definition Entity.cpp:1340
void SetSpeed(const Vector3< double > &speed_)
Definition Entity.cpp:1158
virtual bool IsHangingEntity() const
Definition Entity.cpp:1394
bool GetAreRenderedFacesUpToDate() const
Definition Entity.cpp:1039
virtual void SetMetadataValue(const int index, const std::any &value)
Definition Entity.cpp:772
virtual bool IsSpellcasterIllager() const
Definition Entity.cpp:1365
virtual bool IsBlockAttachedEntity() const
Definition Entity.cpp:1504
static std::shared_ptr< Entity > CreateEntity(const EntityType type)
Definition Entity.cpp:1569
virtual bool IsAbstractThrownPotion() const
Definition Entity.cpp:1439
AABB GetCollider() const
Definition Entity.cpp:349
static const std::array< std::string, metadata_count > metadata_names
Definition Entity.hpp:61
bool are_rendered_faces_up_to_date
Definition Entity.hpp:292
virtual double GetWidthImpl() const
Definition Entity.cpp:2225
virtual void SetZ(const double z_)
Definition Entity.cpp:1110
void SetEquipment(const EquipmentSlot slot, const ProtocolCraft::Slot &item)
Definition Entity.cpp:1188
std::vector< Renderer::Face > faces
Definition Entity.hpp:290
virtual bool IsLivingEntity() const
Definition Entity.cpp:1296
virtual bool IsChestBoat() const
Definition Entity.cpp:1531
double GetWidth() const
Definition Entity.cpp:355
virtual ~Entity()
Definition Entity.cpp:343
virtual bool IsPatrollingMonster() const
Definition Entity.cpp:1485
virtual bool IsProjectile() const
Definition Entity.cpp:1371
int GetDataAirSupplyId() const
Definition Entity.cpp:799
std::vector< EntityEffect > GetEffects() const
Definition Entity.cpp:1011
virtual bool IsAbstractMinecart() const
Definition Entity.cpp:1404
virtual bool IsAvatar() const
Definition Entity.cpp:1548
virtual bool IsDisplay() const
Definition Entity.cpp:1322
void SetSpeedY(const double speed_y_)
Definition Entity.cpp:1170
virtual bool IsAbstractMinecartContainer() const
Definition Entity.cpp:1416
void SetDataCustomName(const std::optional< ProtocolCraft::Chat > &data_custom_name)
Definition Entity.cpp:873
virtual bool IsAmbientCreature() const
Definition Entity.cpp:1311
virtual bool IsFireball() const
Definition Entity.cpp:1399
Pose GetDataPose() const
Definition Entity.cpp:838
std::shared_mutex entity_mutex
Definition Entity.hpp:270
void SetOnGround(const bool on_ground_)
Definition Entity.cpp:1182
virtual bool IsAnimal() const
Definition Entity.cpp:1306
std::vector< Renderer::Face > GetFaces(const bool reset_uptodate_status)
Definition Entity.cpp:1018
void SetSpeedX(const double speed_x_)
Definition Entity.cpp:1164
virtual bool IsAbstractFish() const
Definition Entity.cpp:1445
virtual bool IsAbstractCubeMob() const
Definition Entity.cpp:1562
virtual bool IsAgeableMob() const
Definition Entity.cpp:1474
virtual void SetX(const double x_)
Definition Entity.cpp:1078
virtual bool IsAbstractVillager() const
Definition Entity.cpp:1468
virtual void InitializeFaces()
Definition Entity.cpp:2080
virtual bool IsThrowableProjectile() const
Definition Entity.cpp:1491
virtual bool IsAbstractWindCharge() const
Definition Entity.cpp:1497
AABB GetColliderImpl() const
Definition Entity.cpp:2218
void SetDataSharedFlagsId(const char data_shared_flags_id)
Definition Entity.cpp:854
char GetDataSharedFlagsId() const
Definition Entity.cpp:787
virtual bool IsMob() const
Definition Entity.cpp:1360
virtual void SetYaw(const float yaw_)
Definition Entity.cpp:1126
virtual bool IsPathfinderMob() const
Definition Entity.cpp:1479
ProtocolCraft::Slot GetEquipment(const EquipmentSlot slot) const
Definition Entity.cpp:1005
void SetDataCustomNameVisible(const bool data_custom_name_visible)
Definition Entity.cpp:886
virtual bool IsVehicle() const
Definition Entity.cpp:1329
double GetSpeedY() const
Definition Entity.cpp:981
double GetSpeedZ() const
Definition Entity.cpp:987
Pose GetDataPoseImpl() const
Definition Entity.cpp:2204
virtual bool IsRaider() const
Definition Entity.cpp:1451
virtual void SetPitch(const float pitch_)
Definition Entity.cpp:1142
virtual bool IsThrowableItemProjectile() const
Definition Entity.cpp:1462
void SetEntityID(const int entity_id_)
Definition Entity.cpp:1047
virtual bool IsMonster() const
Definition Entity.cpp:1316
virtual bool IsTamableAnimal() const
Definition Entity.cpp:1335
void SetDataNoGravity(const bool data_no_gravity)
Definition Entity.cpp:898
bool GetDataCustomNameVisible() const
Definition Entity.cpp:819
virtual bool IsAbstractIllager() const
Definition Entity.cpp:1433
virtual bool IsAbstractHorse() const
Definition Entity.cpp:1384
std::map< std::string, std::any > metadata
Definition Entity.hpp:285
Vector3< double > position
Definition Entity.hpp:274
virtual bool IsAbstractCow() const
Definition Entity.cpp:1410
virtual bool IsAbstractChestBoat() const
Definition Entity.cpp:1516
void AddEffect(const EntityEffect &effect)
Definition Entity.cpp:1216
virtual bool IsChestRaft() const
Definition Entity.cpp:1536
virtual bool IsAbstractGolem() const
Definition Entity.cpp:1389
float GetYaw() const
Definition Entity.cpp:957
virtual bool IsAgeableWaterCreature() const
Definition Entity.cpp:1521
double GetX() const
Definition Entity.cpp:939
bool GetDataNoGravity() const
Definition Entity.cpp:831
void SetAreRenderedFacesUpToDate(const bool are_rendered_faces_up_to_date_)
Definition Entity.cpp:1237
Vector3< double > GetPosition() const
Definition Entity.cpp:933
void SetSpeedZ(const double speed_z_)
Definition Entity.cpp:1176
static constexpr int metadata_count
Definition Entity.hpp:55
std::vector< FaceDescriptor > face_descriptors
Definition Entity.hpp:289
std::optional< ProtocolCraft::Chat > GetDataCustomName() const
Definition Entity.cpp:806
virtual bool IsBoat() const
Definition Entity.cpp:1526
void LoadMetadataFromRawArray(const std::vector< unsigned char > &data)
Definition Entity.cpp:368
virtual bool IsRaft() const
Definition Entity.cpp:1541
virtual bool IsShoulderRidingEntity() const
Definition Entity.cpp:1421
float GetPitch() const
Definition Entity.cpp:963
void RemoveEffect(const EntityEffectType type)
Definition Entity.cpp:1200
virtual void SetPosition(const Vector3< double > &position_)
Definition Entity.cpp:1059
void SetDataTicksFrozen(const int data_ticks_frozen)
Definition Entity.cpp:913
const TextureData & GetData(const std::string &name) const
Definition Atlas.cpp:237
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
virtual void Read(ReadIterator &iter, size_t &length)
Vector3< int > Position
Definition Vector3.hpp:294
EquipmentSlot
Definition Enums.hpp:282
EntityEffectType
Definition Enums.hpp:327
EntitySharedFlagsId
Definition Entity.hpp:40
std::array< unsigned char, 16 > UUID
std::vector< unsigned char >::const_iterator ReadIterator
EntityEffectType type
Definition Entity.hpp:34
std::pair< int, int > position
<Col, Row>
Definition Atlas.hpp:16
std::pair< int, int > size
<Width, Height>
Definition Atlas.hpp:14
ProtocolCraft::Json::Value Serialize() const
Definition Vector3.hpp:279