Skip to content

Commit

Permalink
handle nil nbt
Browse files Browse the repository at this point in the history
  • Loading branch information
0123456789-jpg committed Mar 15, 2024
1 parent 3475eae commit 1002124
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions crates/core/item/src/edcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{stack::ItemStackCx, ItemStack, RawItem};

impl<Cx> Encode for ItemStack<'_, Cx>
where
Cx: ItemStackCx + for<'a> WriteNbt<&'a Cx::Compound>,
Cx: ItemStackCx + for<'a> WriteNbt<Option<&'a Cx::Compound>>,
{
fn encode<B>(&self, mut buf: B) -> Result<(), std::io::Error>
where
Expand All @@ -20,12 +20,7 @@ where
item.encode(&mut buf)?;
self.count().encode(&mut buf)?;
if item.settings().max_damage.is_some() || item.settings().sync_nbt {
if let Some(x) = self.nbt() {
Cx::write_nbt(x, buf.writer())?
} else {
// @TODO: Write empty nbt tag.
todo!()
}
Cx::write_nbt(self.nbt(), buf.writer())?
}
}
Ok(())
Expand All @@ -34,7 +29,7 @@ where

impl<'r, Cx> Decode for ItemStack<'r, Cx>
where
Cx: ItemStackCx + for<'a> ReadNbt<&'a Cx::Compound> + ProvideRegistry<'r, Cx::Id, RawItem<Cx>>,
Cx: ItemStackCx + ReadNbt<Option<Cx::Compound>> + ProvideRegistry<'r, Cx::Id, RawItem<Cx>>,
{
fn decode<B>(mut buf: B) -> Result<Self, std::io::Error>
where
Expand All @@ -43,9 +38,8 @@ where
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))
let nbt = Cx::read_nbt(buf.reader())?;
Ok(ItemStack::with_nbt(item, count, nbt))
} else {
Ok(ItemStack::empty())
}
Expand Down

0 comments on commit 1002124

Please sign in to comment.