Skip to main content

steel_protocol/packets/game/
c_set_entity_link.rs

1//! Clientbound set entity link packet.
2
3use steel_macros::{ClientPacket, WriteTo};
4use steel_registry::packets::play::C_SET_ENTITY_LINK;
5
6/// Updates the leash/link holder for an entity.
7#[derive(ClientPacket, WriteTo, Clone, Debug, PartialEq, Eq)]
8#[packet_id(Play = C_SET_ENTITY_LINK)]
9pub struct CSetEntityLink {
10    /// Entity being leashed or cleared.
11    pub source_id: i32,
12    /// Leash holder entity id, or 0 to clear the link.
13    pub dest_id: i32,
14}
15
16impl CSetEntityLink {
17    /// Creates a new entity-link packet.
18    #[must_use]
19    pub const fn new(source_id: i32, dest_id: i32) -> Self {
20        Self { source_id, dest_id }
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use steel_utils::serial::WriteTo as _;
27
28    use super::*;
29
30    #[test]
31    fn entity_link_packet_uses_vanilla_raw_ints() {
32        let packet = CSetEntityLink::new(42, 7);
33        let mut bytes = Vec::new();
34
35        packet.write(&mut bytes).expect("packet should encode");
36
37        assert_eq!(bytes, vec![0, 0, 0, 42, 0, 0, 0, 7]);
38    }
39}