azalea_protocol/packets/game/
c_add_entity.rs

1use azalea_buf::AzBuf;
2use azalea_core::{position::Vec3, resource_location::ResourceLocation};
3use azalea_entity::{metadata::apply_default_metadata, EntityBundle};
4use azalea_protocol_macros::ClientboundGamePacket;
5use azalea_world::MinecraftEntityId;
6use uuid::Uuid;
7
8#[derive(Clone, Debug, AzBuf, ClientboundGamePacket)]
9pub struct ClientboundAddEntity {
10    /// The numeric ID of the entity being added to the world.
11    #[var]
12    pub id: MinecraftEntityId,
13    pub uuid: Uuid,
14    pub entity_type: azalea_registry::EntityKind,
15    pub position: Vec3,
16    pub x_rot: i8,
17    pub y_rot: i8,
18    pub y_head_rot: i8,
19    #[var]
20    pub data: u32,
21    pub x_vel: i16,
22    pub y_vel: i16,
23    pub z_vel: i16,
24}
25
26impl ClientboundAddEntity {
27    /// Make the entity into a bundle that can be inserted into the ECS. You
28    /// must apply the metadata after inserting the bundle with
29    /// [`Self::apply_metadata`].
30    pub fn as_entity_bundle(&self, world_name: ResourceLocation) -> EntityBundle {
31        EntityBundle::new(self.uuid, self.position, self.entity_type, world_name)
32    }
33
34    /// Apply the default metadata for the given entity.
35    pub fn apply_metadata(&self, entity: &mut bevy_ecs::system::EntityCommands) {
36        apply_default_metadata(entity, self.entity_type);
37    }
38}