aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
blob: e76504cc57d9e45410ffb993b65b3d27340758ad (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
use packet_macros::{GamePacket, McBuf};
use std::io::{Read, Write};

#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRecipePacket {
    pub action: State,
    pub settings: RecipeBookSettings,
    pub recipes: Vec<ResourceLocation>,
    pub to_highlight: Vec<ResourceLocation>,
}

#[derive(Clone, Debug, McBuf)]
pub struct RecipeBookSettings {
    pub gui_open: bool,
    pub filtering_craftable: bool,

    pub furnace_gui_open: bool,
    pub furnace_filtering_craftable: bool,

    pub blast_furnace_gui_open: bool,
    pub blast_furnace_filtering_craftable: bool,

    pub smoker_gui_open: bool,
    pub smoker_filtering_craftable: bool,
}

#[derive(Clone, Debug, Copy)]
pub enum State {
    Init = 0,
    Add = 1,
    Remove = 2,
}

impl McBufWritable for State {
    fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
        buf.write_varint(*self as i32)?;
        Ok(())
    }
}
impl McBufReadable for State {
    fn read_into(buf: &mut impl Read) -> Result<Self, String> {
        let state = buf.read_varint()?;
        Ok(match state {
            0 => State::Init,
            1 => State::Add,
            2 => State::Remove,
            _ => panic!("Invalid state: {}", state),
        })
    }
}