1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::network::*;
use crate::packet::*;
use basin2_lib::result::*;
use bytes::BytesMut;

#[derive(PartialEq, Clone, Debug)]
pub struct SetCreativeModeSlotPacket {
    pub slotNum: i16,
    pub itemStack: ItemStack,
}

impl CodablePacket for SetCreativeModeSlotPacket {
    fn encode(self, buf: &mut BytesMut) {
        buf.set_mc_i16(self.slotNum);
        buf.set_mc_item_stack(self.itemStack);
    }

    fn decode(buf: &mut BytesMut) -> Result<Self>
    where
        Self: Sized,
    {
        let slotNum = buf.get_mc_i16()?;
        let itemStack = buf.get_mc_item_stack()?;
        return Ok(SetCreativeModeSlotPacket { slotNum, itemStack });
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::packet::test::*;

    #[test]
    fn test_cycle() -> Result<()> {
        cycle(SetCreativeModeSlotPacket {
            slotNum: 10,
            itemStack: ItemStack::empty(),
        })
    }
}