From 6e818852d868eea963dd2b8489ba75b65c56fb1c Mon Sep 17 00:00:00 2001 From: EightFactorial Date: Mon, 30 Jan 2023 16:18:14 -0800 Subject: More packet fixes, tests, handle error (#61) * Fix packet, fix tests, fixedbitsets * Clippy: Nightmare Mode * Fix mistake * simplify impl Display and make thing pub --------- Co-authored-by: mat --- .../packets/game/serverbound_player_input_packet.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'azalea-protocol/src/packets/game/serverbound_player_input_packet.rs') diff --git a/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs b/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs index 2bd7f6eb..f0c7c548 100755 --- a/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs +++ b/azalea-protocol/src/packets/game/serverbound_player_input_packet.rs @@ -2,6 +2,7 @@ use std::io::Cursor; use azalea_buf::BufReadError; use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_core::FixedBitSet; use azalea_protocol_macros::ServerboundGamePacket; #[derive(Clone, Debug, ServerboundGamePacket)] @@ -16,14 +17,12 @@ impl McBufReadable for ServerboundPlayerInputPacket { fn read_from(buf: &mut Cursor<&[u8]>) -> Result { let xxa = f32::read_from(buf)?; let zza = f32::read_from(buf)?; - let byte = u8::read_from(buf)?; - let is_jumping = byte & 1 != 0; - let is_shift_key_down = byte & 2 != 0; + let set = FixedBitSet::<2>::read_from(buf)?; Ok(Self { xxa, zza, - is_jumping, - is_shift_key_down, + is_jumping: set.index(0), + is_shift_key_down: set.index(1), }) } } @@ -32,14 +31,13 @@ impl McBufWritable for ServerboundPlayerInputPacket { fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { self.xxa.write_into(buf)?; self.zza.write_into(buf)?; - let mut byte = 0u8; + let mut set = FixedBitSet::<2>::new(); if self.is_jumping { - byte |= 1; + set.set(0); } if self.is_shift_key_down { - byte |= 2; + set.set(1); } - byte.write_into(buf)?; - Ok(()) + set.write_into(buf) } } -- cgit v1.2.3