1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

Damage_Event unsigned subtract from zero (#86)

This commit is contained in:
EightFactorial 2023-04-01 16:14:03 -07:00 committed by GitHub
parent ac680d39f2
commit 2907902431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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),
}
}
}