aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/slot.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-23 15:12:17 -0500
committermat <github@matdoes.dev>2022-06-23 15:12:17 -0500
commit5ca49e680ed8519456dc9a9af84321d4b69dcbb3 (patch)
tree0f727c3e862f60eb227db69c87946a0f629a397d /azalea-core/src/slot.rs
parentc7b0c51274b5d8548c8a2f829b75dfbec4038be2 (diff)
downloadazalea-drasl-5ca49e680ed8519456dc9a9af84321d4b69dcbb3.tar.xz
azalea-buf
Diffstat (limited to 'azalea-core/src/slot.rs')
-rw-r--r--azalea-core/src/slot.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/azalea-core/src/slot.rs b/azalea-core/src/slot.rs
index 5e42f558..e3b78289 100644
--- a/azalea-core/src/slot.rs
+++ b/azalea-core/src/slot.rs
@@ -12,3 +12,31 @@ pub struct SlotData {
pub count: u8,
pub nbt: azalea_nbt::Tag,
}
+
+impl McBufReadable for Slot {
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ let present = buf.read_boolean()?;
+ if !present {
+ return Ok(Slot::Empty);
+ }
+ let id = buf.read_varint()?;
+ let count = buf.read_byte()?;
+ let nbt = buf.read_nbt()?;
+ Ok(Slot::Present(SlotData { id, count, nbt }))
+ }
+}
+
+impl McBufWritable for Slot {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ match self {
+ Slot::Empty => buf.write_byte(0)?,
+ Slot::Present(i) => {
+ buf.write_varint(i.id)?;
+ buf.write_byte(i.count)?;
+ buf.write_nbt(&i.nbt)?;
+ }
+ }
+
+ Ok(())
+ }
+}