aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/slot.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-25 05:09:26 +0000
committerGitHub <noreply@github.com>2022-06-25 05:09:26 +0000
commit7d3e57763e32ac9cf94180b1c714704cfbc3034d (patch)
tree2dcfe72bf09a42f6614f9dc988dc0254162ea0bf /azalea-core/src/slot.rs
parent69c47eda4c496b13dadd80976bffd2fab7ea5894 (diff)
parentca7067e173129f3044ebc8c77634f06da29a086e (diff)
downloadazalea-drasl-7d3e57763e32ac9cf94180b1c714704cfbc3034d.tar.xz
Merge pull request #10 from mat-1/azalea-entity
azalea-entity
Diffstat (limited to 'azalea-core/src/slot.rs')
-rw-r--r--azalea-core/src/slot.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/azalea-core/src/slot.rs b/azalea-core/src/slot.rs
index 5e42f558..6e622872 100644
--- a/azalea-core/src/slot.rs
+++ b/azalea-core/src/slot.rs
@@ -1,14 +1,40 @@
// TODO: have an azalea-inventory or azalea-container crate and put this there
+use azalea_buf::{McBuf, McBufReadable, McBufWritable};
+use std::io::{Read, Write};
+
#[derive(Debug, Clone)]
pub enum Slot {
- Present(SlotData),
Empty,
+ Present(SlotData),
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, McBuf)]
pub struct SlotData {
+ #[var]
pub id: i32,
pub count: u8,
pub nbt: azalea_nbt::Tag,
}
+
+impl McBufReadable for Slot {
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ let present = bool::read_into(buf)?;
+ if !present {
+ return Ok(Slot::Empty);
+ }
+ let slot = SlotData::read_into(buf)?;
+ Ok(Slot::Present(slot))
+ }
+}
+
+impl McBufWritable for Slot {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ match self {
+ Slot::Empty => 0u8.write_into(buf)?,
+ Slot::Present(i) => i.write_into(buf)?,
+ }
+
+ Ok(())
+ }
+}