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