Skip to main content

steel_protocol/packets/game/
c_take_item_entity.rs

1//! Clientbound take item entity packet - sent when an entity picks up an item.
2//!
3//! Triggers the pickup animation and sound on the client. The item entity
4//! will fly towards the collector before being removed.
5
6use std::io::{Result, Write};
7
8use steel_macros::ClientPacket;
9use steel_registry::packets::play::C_TAKE_ITEM_ENTITY;
10use steel_utils::{codec::VarInt, serial::WriteTo};
11
12/// Sent when an entity picks up an item (item, experience orb, or arrow).
13///
14/// Triggers the pickup animation on the client where the item entity
15/// flies towards the collector entity before disappearing.
16///
17/// Corresponds to vanilla's `ClientboundTakeItemEntityPacket`.
18#[derive(ClientPacket, Clone, Debug)]
19#[packet_id(Play = C_TAKE_ITEM_ENTITY)]
20pub struct CTakeItemEntity {
21    /// The entity ID of the item being picked up.
22    pub item_id: i32,
23    /// The entity ID of the collector (player or other entity).
24    pub player_id: i32,
25    /// The number of items picked up (for animation/sound).
26    pub amount: i32,
27}
28
29impl CTakeItemEntity {
30    /// Creates a new take item entity packet.
31    #[must_use]
32    pub const fn new(item_id: i32, player_id: i32, amount: i32) -> Self {
33        Self {
34            item_id,
35            player_id,
36            amount,
37        }
38    }
39}
40
41impl WriteTo for CTakeItemEntity {
42    fn write(&self, writer: &mut impl Write) -> Result<()> {
43        VarInt(self.item_id).write(writer)?;
44        VarInt(self.player_id).write(writer)?;
45        VarInt(self.amount).write(writer)
46    }
47}