367 if (data.size() == 0)
373 size_t length = data.size();
377 const unsigned char index = ProtocolCraft::ReadData<unsigned char>(iter, length);
383 const int type = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length);
386 enum EntityMetadataTypes
390#if PROTOCOL_VERSION > 760
396#if PROTOCOL_VERSION > 340
403 OptionalBlockPosition,
405#if PROTOCOL_VERSION > 769
406 OptionalLivingEntityReference,
411#if PROTOCOL_VERSION > 761
414#if PROTOCOL_VERSION < 773
417#if PROTOCOL_VERSION > 340
420#if PROTOCOL_VERSION > 765
423#if PROTOCOL_VERSION > 404
428#if PROTOCOL_VERSION > 758
431#if PROTOCOL_VERSION > 769
434#if PROTOCOL_VERSION > 765
437#if PROTOCOL_VERSION > 769
440#if PROTOCOL_VERSION > 758
443#if PROTOCOL_VERSION > 769
447#if PROTOCOL_VERSION > 773
448 ZombieNautilusVariant,
450#if PROTOCOL_VERSION > 758
454#if PROTOCOL_VERSION > 761
456#if PROTOCOL_VERSION > 765
459#if PROTOCOL_VERSION > 772
461 WeatheringCopperState,
465#if PROTOCOL_VERSION > 772
469#if PROTOCOL_VERSION > 773
476 case EntityMetadataTypes::Char:
477 value = ProtocolCraft::ReadData<char>(iter, length);
479 case EntityMetadataTypes::Int:
480 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
482#if PROTOCOL_VERSION > 760
483 case EntityMetadataTypes::Long:
484 value =
static_cast<long long int>(ProtocolCraft::ReadData<ProtocolCraft::VarLong>(iter, length));
487 case EntityMetadataTypes::Float:
488 value = ProtocolCraft::ReadData<float>(iter, length);
490 case EntityMetadataTypes::String:
491 value = ProtocolCraft::ReadData<std::string>(iter, length);
493 case EntityMetadataTypes::Chat:
495 std::any_cast<ProtocolCraft::Chat&>(value).Read(iter, length);
497#if PROTOCOL_VERSION > 340
498 case EntityMetadataTypes::OptionalChat:
499 if (ProtocolCraft::ReadData<bool>(iter, length))
502 std::any_cast<std::optional<ProtocolCraft::Chat>&>(value).value().Read(iter, length);
506 value = std::optional<ProtocolCraft::Chat>();
510 case EntityMetadataTypes::Slot:
512 std::any_cast<ProtocolCraft::Slot&>(value).Read(iter, length);
514 case EntityMetadataTypes::Bool:
515 value = ProtocolCraft::ReadData<bool>(iter, length);
517 case EntityMetadataTypes::Rotations:
520 for (
int i = 0; i < 3; ++i)
522 rotation[i] = ProtocolCraft::ReadData<float>(iter, length);
527 case EntityMetadataTypes::BlockPosition:
534 case EntityMetadataTypes::OptionalBlockPosition:
535 if (ProtocolCraft::ReadData<bool>(iter, length))
539 value = std::optional<Position>(
position);
543 value = std::optional<Position>();
546 case EntityMetadataTypes::DirectionType:
547 value =
static_cast<Direction>(
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length)));
549#if PROTOCOL_VERSION > 769
550 case EntityMetadataTypes::OptionalLivingEntityReference:
552 case EntityMetadataTypes::OptionalUUID:
554 if (ProtocolCraft::ReadData<bool>(iter, length))
556 value = std::optional<ProtocolCraft::UUID>(ProtocolCraft::ReadData<ProtocolCraft::UUID>(iter, length));
560 value = std::optional<ProtocolCraft::UUID>();
563 case EntityMetadataTypes::BlockstateType:
564 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
566#if PROTOCOL_VERSION > 761
567 case EntityMetadataTypes::OptionalBlockstate:
568 if (
const int n = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length))
570 value = std::optional<int>(n);
574 value = std::optional<int>();
578#if PROTOCOL_VERSION < 773
579 case EntityMetadataTypes::NBT:
582 unnamed_value.
Read(iter, length);
587#if PROTOCOL_VERSION > 340
588 case EntityMetadataTypes::Particle:
591 particle.
Read(iter, length);
596#if PROTOCOL_VERSION > 765
597 case EntityMetadataTypes::Particles:
598 value = ProtocolCraft::ReadData<std::vector<ProtocolCraft::Particle>>(iter, length);
601#if PROTOCOL_VERSION > 404
602 case EntityMetadataTypes::VillagerDataType:
604 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length),
605 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length),
606 ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length)
609 case EntityMetadataTypes::OptionalUint:
611 const int val = ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length);
612 value = val > 0 ? std::optional<int>(val - 1) : std::optional<int>();
615 case EntityMetadataTypes::PoseType:
616 value =
static_cast<Pose>(
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length)));
619#if PROTOCOL_VERSION > 758
620 case EntityMetadataTypes::CatVariant:
621 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
624#if PROTOCOL_VERSION > 769
625 case EntityMetadataTypes::CowVariant:
626 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
629#if PROTOCOL_VERSION > 765
630 case EntityMetadataTypes::WolfVariant:
631 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
634#if PROTOCOL_VERSION > 769
635 case EntityMetadataTypes::WolfSoundVariant:
636 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
639#if PROTOCOL_VERSION > 758
640 case EntityMetadataTypes::FrogVariant:
641 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
644#if PROTOCOL_VERSION > 769
645 case EntityMetadataTypes::PigVariant:
646 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
648 case EntityMetadataTypes::ChickenVariant:
649 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
652#if PROTOCOL_VERSION > 773
653 case EntityMetadataTypes::ZombieNautilusVariant:
654 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
657#if PROTOCOL_VERSION > 758
658 case EntityMetadataTypes::OptionalGlobalPos:
659 if (ProtocolCraft::ReadData<bool>(iter, length))
662 dimension.
Read(iter, length);
664 pos.
Read(iter, length);
666 value = std::optional<GlobalPos>({
673 value = std::optional<GlobalPos>();
676 case EntityMetadataTypes::PaintingVariant:
677 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
680#if PROTOCOL_VERSION > 761
681 case EntityMetadataTypes::SnifferState:
682 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
684#if PROTOCOL_VERSION > 765
685 case EntityMetadataTypes::ArmadilloState:
686 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
689#if PROTOCOL_VERSION > 772
690 case EntityMetadataTypes::CopperGolemState:
691 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
693 case EntityMetadataTypes::WeatheringCopperState:
694 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
697 case EntityMetadataTypes::Vec3:
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);
705 case EntityMetadataTypes::Quaternion:
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};
715#if PROTOCOL_VERSION > 772
716 case EntityMetadataTypes::ResolvableProfile:
717 value = ProtocolCraft::ReadData<ProtocolCraft::Components::DataComponentTypeResolvableProfile>(iter, length);
720#if PROTOCOL_VERSION > 773
721 case EntityMetadataTypes::HumanoidArm:
722 value =
static_cast<int>(ProtocolCraft::ReadData<ProtocolCraft::VarInt>(iter, length));
726 LOG_ERROR(
"Unknown type in entity metadata : " << type <<
".Stopping current metadata parsing.");
1529#if PROTOCOL_VERSION > 758
1531 return std::make_shared<AllayEntity>();
1534 return std::make_shared<AreaEffectCloudEntity>();
1535#if PROTOCOL_VERSION > 765
1537 return std::make_shared<ArmadilloEntity>();
1540 return std::make_shared<ArmorStandEntity>();
1542 return std::make_shared<ArrowEntity>();
1543#if PROTOCOL_VERSION > 754
1545 return std::make_shared<AxolotlEntity>();
1548 return std::make_shared<BatEntity>();
1549#if PROTOCOL_VERSION > 498
1551 return std::make_shared<BeeEntity>();
1554 return std::make_shared<BlazeEntity>();
1555#if PROTOCOL_VERSION < 768
1556 case EntityType::Boat:
1557 return std::make_shared<BoatEntity>();
1568 return std::make_shared<BoatEntity>(type);
1570#if PROTOCOL_VERSION > 765
1572 return std::make_shared<BoggedEntity>();
1574#if PROTOCOL_VERSION > 764
1576 return std::make_shared<BreezeEntity>();
1578#if PROTOCOL_VERSION > 765
1580 return std::make_shared<BreezeWindChargeEntity>();
1582#if PROTOCOL_VERSION > 758
1583#if PROTOCOL_VERSION < 768
1584 case EntityType::ChestBoat:
1585 return std::make_shared<ChestBoatEntity>();
1596 return std::make_shared<ChestBoatEntity>(type);
1599#if PROTOCOL_VERSION > 767
1601 return std::make_shared<ChestRaftEntity>(type);
1603#if PROTOCOL_VERSION > 404
1605 return std::make_shared<CatEntity>();
1607#if PROTOCOL_VERSION > 760
1609 return std::make_shared<CamelEntity>();
1611#if PROTOCOL_VERSION > 773
1613 return std::make_shared<CamelHuskEntity>();
1616 return std::make_shared<CaveSpiderEntity>();
1618 return std::make_shared<ChickenEntity>();
1619#if PROTOCOL_VERSION > 340
1621 return std::make_shared<CodEntity>();
1623#if PROTOCOL_VERSION > 772
1625 return std::make_shared<CopperGolemEntity>();
1628 return std::make_shared<CowEntity>();
1629#if PROTOCOL_VERSION > 767
1631 return std::make_shared<CreakingEntity>();
1633#if PROTOCOL_VERSION > 767 && PROTOCOL_VERSION < 769
1634 case EntityType::CreakingTransient:
1635 return std::make_shared<CreakingTransientEntity>();
1638 return std::make_shared<CreeperEntity>();
1639#if PROTOCOL_VERSION > 761
1641 return std::make_shared<DisplayBlockDisplayEntity>();
1643 return std::make_shared<DisplayItemDisplayEntity>();
1645 return std::make_shared<DisplayTextDisplayEntity>();
1647#if PROTOCOL_VERSION > 340
1649 return std::make_shared<DolphinEntity>();
1652 return std::make_shared<DonkeyEntity>();
1654 return std::make_shared<DragonFireballEntity>();
1655#if PROTOCOL_VERSION > 340
1657 return std::make_shared<DrownedEntity>();
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>();
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
1683 return std::make_shared<FoxEntity>();
1685#if PROTOCOL_VERSION > 758
1687 return std::make_shared<FrogEntity>();
1690 return std::make_shared<GhastEntity>();
1691#if PROTOCOL_VERSION > 770
1693 return std::make_shared<HappyGhastEntity>();
1696 return std::make_shared<GiantEntity>();
1697#if PROTOCOL_VERSION > 754
1699 return std::make_shared<GlowItemFrameEntity>();
1701 return std::make_shared<GlowSquidEntity>();
1703 return std::make_shared<GoatEntity>();
1706 return std::make_shared<GuardianEntity>();
1707#if PROTOCOL_VERSION > 578
1709 return std::make_shared<HoglinEntity>();
1712 return std::make_shared<HorseEntity>();
1714 return std::make_shared<HuskEntity>();
1716 return std::make_shared<IllusionerEntity>();
1717#if PROTOCOL_VERSION > 761
1719 return std::make_shared<InteractionEntity>();
1722 return std::make_shared<IronGolemEntity>();
1724 return std::make_shared<ItemEntity>();
1726 return std::make_shared<ItemFrameEntity>();
1727#if PROTOCOL_VERSION > 765
1729 return std::make_shared<OminousItemSpawnerEntity>();
1732 return std::make_shared<LargeFireballEntity>();
1734 return std::make_shared<LeashFenceKnotEntity>();
1735#if PROTOCOL_VERSION > 340
1737 return std::make_shared<LightningBoltEntity>();
1740 return std::make_shared<LlamaEntity>();
1742 return std::make_shared<LlamaSpitEntity>();
1744 return std::make_shared<MagmaCubeEntity>();
1745#if PROTOCOL_VERSION > 772
1747 return std::make_shared<MannequinEntity>();
1749#if PROTOCOL_VERSION > 754
1751 return std::make_shared<MarkerEntity>();
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>();
1768 return std::make_shared<MuleEntity>();
1769#if PROTOCOL_VERSION > 773
1771 return std::make_shared<NautilusEntity>();
1774 return std::make_shared<MushroomCowEntity>();
1776 return std::make_shared<OcelotEntity>();
1778 return std::make_shared<PaintingEntity>();
1779#if PROTOCOL_VERSION > 404
1781 return std::make_shared<PandaEntity>();
1783#if PROTOCOL_VERSION > 773
1785 return std::make_shared<ParchedEntity>();
1788 return std::make_shared<ParrotEntity>();
1789#if PROTOCOL_VERSION > 340
1791 return std::make_shared<PhantomEntity>();
1794 return std::make_shared<PigEntity>();
1795#if PROTOCOL_VERSION > 578
1797 return std::make_shared<PiglinEntity>();
1799#if PROTOCOL_VERSION > 736
1801 return std::make_shared<PiglinBruteEntity>();
1803#if PROTOCOL_VERSION > 404
1805 return std::make_shared<PillagerEntity>();
1808 return std::make_shared<PolarBearEntity>();
1810 return std::make_shared<PrimedTntEntity>();
1811#if PROTOCOL_VERSION > 340
1813 return std::make_shared<PufferfishEntity>();
1816 return std::make_shared<RabbitEntity>();
1817#if PROTOCOL_VERSION > 767
1819 return std::make_shared<RaftEntity>(type);
1821#if PROTOCOL_VERSION > 404
1823 return std::make_shared<RavagerEntity>();
1825#if PROTOCOL_VERSION > 340
1827 return std::make_shared<SalmonEntity>();
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>();
1842 return std::make_shared<SlimeEntity>();
1844 return std::make_shared<SmallFireballEntity>();
1845#if PROTOCOL_VERSION > 761
1847 return std::make_shared<SnifferEntity>();
1850 return std::make_shared<SnowGolemEntity>();
1852 return std::make_shared<SnowballEntity>();
1854 return std::make_shared<SpectralArrowEntity>();
1856 return std::make_shared<SpiderEntity>();
1858 return std::make_shared<SquidEntity>();
1860 return std::make_shared<StrayEntity>();
1861#if PROTOCOL_VERSION > 578
1863 return std::make_shared<StriderEntity>();
1865#if PROTOCOL_VERSION > 758
1867 return std::make_shared<TadpoleEntity>();
1870 return std::make_shared<ThrownEggEntity>();
1872 return std::make_shared<ThrownEnderpearlEntity>();
1874 return std::make_shared<ThrownExperienceBottleEntity>();
1875#if PROTOCOL_VERSION < 770
1876 case EntityType::ThrownPotion:
1877 return std::make_shared<ThrownPotionEntity>();
1880 return std::make_shared<ThrownSplashPotionEntity>();
1882 return std::make_shared<ThrownLingeringPotionEntity>();
1884#if PROTOCOL_VERSION > 340
1886 return std::make_shared<ThrownTridentEntity>();
1888#if PROTOCOL_VERSION > 404
1890 return std::make_shared<TraderLlamaEntity>();
1892#if PROTOCOL_VERSION > 340
1894 return std::make_shared<TropicalFishEntity>();
1896#if PROTOCOL_VERSION > 340
1898 return std::make_shared<TurtleEntity>();
1901 return std::make_shared<VexEntity>();
1903 return std::make_shared<VillagerEntity>();
1905 return std::make_shared<VindicatorEntity>();
1906#if PROTOCOL_VERSION > 404
1908 return std::make_shared<WanderingTraderEntity>();
1910#if PROTOCOL_VERSION > 758
1912 return std::make_shared<WardenEntity>();
1914#if PROTOCOL_VERSION > 764
1916 return std::make_shared<WindChargeEntity>();
1919 return std::make_shared<WitchEntity>();
1921 return std::make_shared<WitherBossEntity>();
1923 return std::make_shared<WitherSkeletonEntity>();
1925 return std::make_shared<WitherSkullEntity>();
1927 return std::make_shared<WolfEntity>();
1928#if PROTOCOL_VERSION > 578
1930 return std::make_shared<ZoglinEntity>();
1933 return std::make_shared<ZombieEntity>();
1935 return std::make_shared<ZombieHorseEntity>();
1936#if PROTOCOL_VERSION > 773
1938 return std::make_shared<ZombieNautilusEntity>();
1941 return std::make_shared<ZombieVillagerEntity>();
1942#if PROTOCOL_VERSION > 578
1944 return std::make_shared<ZombifiedPiglinEntity>();
1946 case EntityType::PigZombie:
1947 return std::make_shared<PigZombieEntity>();
1950 return std::make_shared<PlayerEntity>();
1951#if PROTOCOL_VERSION > 340
1953 return std::make_shared<FishingHookEntity>();
2032 std::scoped_lock<std::shared_mutex> lock(
entity_mutex);
2037 faces = std::vector<Renderer::Face>(6);
2040 for (
int i = 0; i < 6; ++i)
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)
2054 face_descriptors[i].transformations.translations.push_back(std::make_shared<Renderer::Translation>(0.0f,
static_cast<float>(half_height), 0.0f));
2056 face_descriptors[i].transformations.translations.push_back(std::make_shared<Renderer::Translation>(
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));
2068 faces[i].SetDisplayBackface(
false);
2069 faces[i].SetTextureMultipliers({ 0xFFFFFFFF, 0xFFFFFFFF });
2072 std::array<unsigned short, 4> texture_pos = { 0, 0, 0, 0 };
2073 std::array<unsigned short, 4> texture_size = { 0, 0, 0, 0 };
2077 for (
int j = 0; j < std::min(2, static_cast<int>(
face_descriptors[i].texture_names.size())); ++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;
2087 std::array<float, 4> coords =
faces[i].GetTextureCoords(
false);
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);
2098 coords =
faces[i].GetTextureCoords(
true);
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);
2107 faces[i].SetTransparencyData(transparencies[0]);