Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 2, 2023
1 parent e83c50b commit 22ad0e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
66 changes: 52 additions & 14 deletions azalea-chat/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@ fn serde_serialize_field<S: serde::ser::SerializeStruct>(
name: &'static str,
value: &Option<impl serde::Serialize>,
default: &(impl serde::Serialize + ?Sized),
reset: bool,
) -> Result<(), S::Error> {
if let Some(value) = value {
state.serialize_field(name, value)?;
} else {
} else if reset {
state.serialize_field(name, default)?;
}
Ok(())
Expand All @@ -336,10 +337,11 @@ fn simdnbt_serialize_field(
name: &'static str,
value: Option<impl simdnbt::ToNbtTag>,
default: impl simdnbt::ToNbtTag,
reset: bool,
) {
if let Some(value) = value {
compound.insert(name, value);
} else {
} else if reset {
compound.insert(name, default);
}
}
Expand All @@ -361,12 +363,30 @@ impl Serialize for Style {
};
let mut state = serializer.serialize_struct("Style", len)?;

serde_serialize_field(&mut state, "color", &self.color, "white")?;
serde_serialize_field(&mut state, "bold", &self.bold, &false)?;
serde_serialize_field(&mut state, "italic", &self.italic, &false)?;
serde_serialize_field(&mut state, "underlined", &self.underlined, &false)?;
serde_serialize_field(&mut state, "strikethrough", &self.strikethrough, &false)?;
serde_serialize_field(&mut state, "obfuscated", &self.obfuscated, &false)?;
serde_serialize_field(&mut state, "color", &self.color, "white", self.reset)?;
serde_serialize_field(&mut state, "bold", &self.bold, &false, self.reset)?;
serde_serialize_field(&mut state, "italic", &self.italic, &false, self.reset)?;
serde_serialize_field(
&mut state,
"underlined",
&self.underlined,
&false,
self.reset,
)?;
serde_serialize_field(
&mut state,
"strikethrough",
&self.strikethrough,
&false,
self.reset,
)?;
serde_serialize_field(
&mut state,
"obfuscated",
&self.obfuscated,
&false,
self.reset,
)?;

state.end()
}
Expand All @@ -377,12 +397,30 @@ impl simdnbt::Serialize for Style {
fn to_compound(self) -> NbtCompound {
let mut compound = NbtCompound::new();

simdnbt_serialize_field(&mut compound, "color", self.color, "white");
simdnbt_serialize_field(&mut compound, "bold", self.bold, false);
simdnbt_serialize_field(&mut compound, "italic", self.italic, false);
simdnbt_serialize_field(&mut compound, "underlined", self.underlined, false);
simdnbt_serialize_field(&mut compound, "strikethrough", self.strikethrough, false);
simdnbt_serialize_field(&mut compound, "obfuscated", self.obfuscated, false);
simdnbt_serialize_field(&mut compound, "color", self.color, "white", self.reset);
simdnbt_serialize_field(&mut compound, "bold", self.bold, false, self.reset);
simdnbt_serialize_field(&mut compound, "italic", self.italic, false, self.reset);
simdnbt_serialize_field(
&mut compound,
"underlined",
self.underlined,
false,
self.reset,
);
simdnbt_serialize_field(
&mut compound,
"strikethrough",
self.strikethrough,
false,
self.reset,
);
simdnbt_serialize_field(
&mut compound,
"obfuscated",
self.obfuscated,
false,
self.reset,
);

compound
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct ClientboundExplodePacket {
pub explosion_sound: SoundEvent,
}

#[derive(Clone, Debug, PartialEq, McBuf)]
#[derive(Clone, Copy, Debug, PartialEq, McBuf)]
pub enum BlockInteraction {
Keep,
Destroy,
Expand Down Expand Up @@ -108,6 +108,7 @@ impl McBufWritable for ClientboundExplodePacket {
self.block_interaction.write_into(buf)?;
self.small_explosion_particles.write_into(buf)?;
self.large_explosion_particles.write_into(buf)?;
self.explosion_sound.write_into(buf)?;

Ok(())
}
Expand Down

0 comments on commit 22ad0e9

Please sign in to comment.