diff options
| author | EightFactorial <29801334+EightFactorial@users.noreply.github.com> | 2023-04-01 16:14:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-01 18:14:03 -0500 |
| commit | 290790243129b4eda12c4732c64bb6874449c9ea (patch) | |
| tree | cc37ce3e5d4db8e0ebb7b15efbc4803585319672 | |
| parent | ac680d39f23f0fe004970fb9e48ca9a60437f607 (diff) | |
| download | azalea-drasl-290790243129b4eda12c4732c64bb6874449c9ea.tar.xz | |
Damage_Event unsigned subtract from zero (#86)
| -rw-r--r-- | azalea-protocol/src/packets/game/clientbound_damage_event_packet.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_damage_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_damage_event_packet.rs index 93731445..941ed01f 100644 --- a/azalea-protocol/src/packets/game/clientbound_damage_event_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_damage_event_packet.rs @@ -16,15 +16,20 @@ pub struct ClientboundDamageEventPacket { } #[derive(Clone, Debug)] -pub struct OptionalEntityId(pub u32); +pub struct OptionalEntityId(pub Option<u32>); impl McBufReadable for OptionalEntityId { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> { - Ok(OptionalEntityId(u32::var_read_from(buf)? - 1)) + match u32::var_read_from(buf)? { + 0 => Ok(OptionalEntityId(None)), + id => Ok(OptionalEntityId(Some(id - 1))), + } } } impl McBufWritable for OptionalEntityId { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { - (self.0 + 1).var_write_into(buf)?; - Ok(()) + match self.0 { + Some(id) => (id + 1).var_write_into(buf), + None => 0u32.var_write_into(buf), + } } } |
