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