Skip to main content

steel_protocol/packets/game/
c_set_player_inventory.rs

1//! Clientbound player inventory slot update packet.
2
3use steel_macros::{ClientPacket, WriteTo};
4use steel_registry::{item_stack::ItemStack, packets::play::C_SET_PLAYER_INVENTORY};
5
6/// Updates one logical slot in the receiving player's inventory.
7#[derive(ClientPacket, WriteTo, Clone, Debug)]
8#[packet_id(Play = C_SET_PLAYER_INVENTORY)]
9pub struct CSetPlayerInventory {
10    #[write(as = VarInt)]
11    pub slot: i32,
12    pub item_stack: ItemStack,
13}
14
15#[cfg(test)]
16mod tests {
17    use steel_utils::serial::WriteTo as _;
18
19    use super::*;
20
21    #[test]
22    fn player_inventory_slot_is_encoded_as_varint_before_item_stack() {
23        let packet = CSetPlayerInventory {
24            slot: 300,
25            item_stack: ItemStack::empty(),
26        };
27        let mut bytes = Vec::new();
28
29        packet.write(&mut bytes).expect("packet should encode");
30
31        assert_eq!(bytes, vec![0xac, 0x02, 0]);
32    }
33}