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