Skip to content

Commit

Permalink
ItemStack decode
Browse files Browse the repository at this point in the history
  • Loading branch information
0123456789-jpg committed Mar 15, 2024
1 parent 9acbe7d commit 3475eae
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions crates/core/item/src/edcode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rimecraft_edcode::Encode;
use rimecraft_global_cx::nbt_edcode::WriteNbt;
use rimecraft_edcode::{Decode, Encode};
use rimecraft_global_cx::nbt_edcode::{ReadNbt, WriteNbt};
use rimecraft_registry::{ProvideRegistry, Reg};

use crate::{stack::ItemStackCx, ItemStack};
use crate::{stack::ItemStackCx, ItemStack, RawItem};

impl<Cx> Encode for ItemStack<'_, Cx>
where
Expand All @@ -22,11 +23,31 @@ where
if let Some(x) = self.nbt() {
Cx::write_nbt(x, buf.writer())?
} else {
// Write empty nbt tag.
// @TODO: Write empty nbt tag.
todo!()
}
}
}
Ok(())
}
}

impl<'r, Cx> Decode for ItemStack<'r, Cx>
where
Cx: ItemStackCx + for<'a> ReadNbt<&'a Cx::Compound> + ProvideRegistry<'r, Cx::Id, RawItem<Cx>>,
{
fn decode<B>(mut buf: B) -> Result<Self, std::io::Error>
where
B: rimecraft_edcode::bytes::Buf,
{
if bool::decode(&mut buf)? {
let item = Reg::<'r, Cx::Id, RawItem<Cx>>::decode(&mut buf)?;
let count = u8::decode(&mut buf)?;
// @TODO: Handle null tags.
let nbt = todo!();
// Ok(ItemStack::with_nbt(item, count, nbt))
} else {
Ok(ItemStack::empty())
}
}
}

0 comments on commit 3475eae

Please sign in to comment.