From 036d8b8b4442abe5f3f2f552842f9b23cd7d585e Mon Sep 17 00:00:00 2001 From: Guac <60993440+guac42@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:27:02 -0600 Subject: [PATCH] Fix encoding villager level in `TrackedData` (#543) Fix encoding villager level in `TrackedData`. The level should be encoded as a `VarInt` when it was being encoded as an `i32`. # Objective - Fixes #453 # Solution - The level should be encoded as a `VarInt` when it was being encoded as an `i32`. --- crates/valence_entity/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/valence_entity/src/lib.rs b/crates/valence_entity/src/lib.rs index f66ffa79f..4f3696ce6 100644 --- a/crates/valence_entity/src/lib.rs +++ b/crates/valence_entity/src/lib.rs @@ -382,7 +382,7 @@ impl EntityAnimations { #[derive(Component, Default, Debug, Deref, DerefMut)] pub struct ObjectData(pub i32); -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encode, Decode)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct VillagerData { pub kind: VillagerKind, pub profession: VillagerProfession, @@ -409,6 +409,24 @@ impl Default for VillagerData { } } +impl Encode for VillagerData { + fn encode(&self, mut w: impl std::io::Write) -> anyhow::Result<()> { + self.kind.encode(&mut w)?; + self.profession.encode(&mut w)?; + VarInt(self.level).encode(w) + } +} + +impl Decode<'_> for VillagerData { + fn decode(r: &mut &[u8]) -> anyhow::Result { + Ok(Self { + kind: VillagerKind::decode(r)?, + profession: VillagerProfession::decode(r)?, + level: VarInt::decode(r)?.0, + }) + } +} + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encode, Decode)] pub enum VillagerKind { Desert,