diff options
| author | EightFactorial <murphkev000@gmail.com> | 2023-01-30 16:18:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-30 18:18:14 -0600 |
| commit | 6e818852d868eea963dd2b8489ba75b65c56fb1c (patch) | |
| tree | e786e919de7d4a1777d91e8e2fa890482970972d /azalea-protocol/src/packets/game/serverbound_player_input_packet.rs | |
| parent | 2539f948c7a88a86b27b1878f6c28976285f348c (diff) | |
| download | azalea-drasl-6e818852d868eea963dd2b8489ba75b65c56fb1c.tar.xz | |
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 <github@matdoes.dev>
Diffstat (limited to 'azalea-protocol/src/packets/game/serverbound_player_input_packet.rs')
| -rwxr-xr-x | azalea-protocol/src/packets/game/serverbound_player_input_packet.rs | 18 |
1 files changed, 8 insertions, 10 deletions
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<Self, BufReadError> { 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) } } |
