Skip to content

Commit

Permalink
Fix encoding villager level in TrackedData (valence-rs#543)
Browse files Browse the repository at this point in the history
Fix encoding villager level in `TrackedData`. The level should be
encoded as a `VarInt` when it was being encoded as an `i32`.

# Objective

- Fixes valence-rs#453 

# Solution

- The level should be encoded as a `VarInt` when it was being encoded as
an `i32`.
guac42 authored Oct 4, 2023
1 parent a46764c commit 036d8b8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/valence_entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Self> {
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,

0 comments on commit 036d8b8

Please sign in to comment.