Skip to main content

steel_protocol/packets/game/
c_block_event.rs

1use steel_macros::{ClientPacket, WriteTo};
2use steel_registry::packets::play::C_BLOCK_EVENT;
3use steel_utils::BlockPos;
4
5/// Sent to trigger block-specific events on the client.
6///
7/// Block events are used for special block behaviors like:
8/// - Pistons extending/retracting
9/// - Note blocks playing notes
10/// - Chest lid opening/closing
11/// - Ender chests
12/// - Bells ringing
13///
14/// Each block type interprets the `action_id` and `action_param` differently.
15#[derive(WriteTo, ClientPacket, Clone, Debug)]
16#[packet_id(Play = C_BLOCK_EVENT)]
17pub struct CBlockEvent {
18    /// The position of the block.
19    pub pos: BlockPos,
20    /// The action ID (block-specific meaning).
21    pub action_id: u8,
22    /// The action parameter (block-specific meaning).
23    pub action_param: u8,
24    /// The block registry ID.
25    /// Written as `VarInt`.
26    #[write(as = VarInt)]
27    pub block_id: i32,
28}
29
30impl CBlockEvent {
31    /// Creates a new block event packet.
32    #[must_use]
33    pub const fn new(pos: BlockPos, action_id: u8, action_param: u8, block_id: i32) -> Self {
34        Self {
35            pos,
36            action_id,
37            action_param,
38            block_id,
39        }
40    }
41}