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