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
use binary_utils::{DataWriter, write_bytes, Error};
use datatypes::ImportantFunctions;
use nbt_lib::{version::JavaNetty, traits::NbtWrite};
use tokio::io::AsyncWrite;

use crate::Slot;

impl DataWriter for Slot {
    async fn write(&self, writer: &mut (impl AsyncWrite + Unpin)) -> binary_utils::Result<()> {
        match self {
            Self::Empty => datatypes::Boolean::new(false).write(writer).await,
            Self::Data(id, count, nbt) => {
                let mut data = Vec::new();
                datatypes::Boolean::new(true).write(&mut data).await?;
                datatypes::VarInt::new(*id).write(&mut data).await?;
                datatypes::Byte::new(*count).write(&mut data).await?;
                if let Some(nbt) = nbt {
                    if let Err(_) = JavaNetty::write_to(&nbt, &mut data) {
                        return Err(Error::FailedToWrite);
                    }
                } else {
                    write_bytes(&mut data, &[0]).await?;
                }
                write_bytes(writer, &data).await
            }
        }
    }
}
impl ImportantFunctions for Slot {
    type InputType = (Option<i32>, Option<i8>, Option<nbt_lib::NbtValue>);
    type ReturnType = Self::InputType;

    fn new(data: Self::InputType) -> Self {
        if data.0.is_some() && data.1.is_some() {
            return Self::Data(data.0.unwrap_or(0), data.1.unwrap_or(0), data.2);
        }
        Self::Empty
    }

    fn get_value(&self) -> Self::ReturnType {
        todo!()
    }
}