mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
use pumpkin_data::packet::clientbound::PLAY_PLAYER_ABILITIES;
|
|
use pumpkin_macros::java_packet;
|
|
|
|
use crate::ClientPacket;
|
|
use crate::ser::NetworkWriteExt;
|
|
use pumpkin_util::version::JavaMinecraftVersion;
|
|
|
|
/// Updates the player's movement and interaction abilities.
|
|
///
|
|
/// This packet informs the client about the player's state (flying, invulnerable)
|
|
/// and sets the movement speeds. While the client applies these visuals,
|
|
/// the server must still validate these states to prevent cheating.
|
|
#[java_packet(PLAY_PLAYER_ABILITIES)]
|
|
pub struct CPlayerAbilities {
|
|
/// A bitmask of player states.
|
|
/// Bit 0 (0x01): Invulnerable (Creative mode)
|
|
/// Bit 1 (0x02): Flying
|
|
/// Bit 2 (0x04): Allow Flying
|
|
/// Bit 3 (0x08): Creative Mode (Instant Break)
|
|
pub flags: i8,
|
|
/// The multiplier for flying speed.
|
|
/// Default is 0.05.
|
|
pub flying_speed: f32,
|
|
/// The field of view modifier (Walking speed multiplier).
|
|
/// Default is 0.1.
|
|
pub field_of_view: f32,
|
|
}
|
|
|
|
impl CPlayerAbilities {
|
|
#[must_use]
|
|
pub const fn new(flags: i8, flying_speed: f32, field_of_view: f32) -> Self {
|
|
Self {
|
|
flags,
|
|
flying_speed,
|
|
field_of_view,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ClientPacket for CPlayerAbilities {
|
|
fn write_packet_data(
|
|
&self,
|
|
mut write: impl std::io::Write,
|
|
_version: &JavaMinecraftVersion,
|
|
) -> Result<(), crate::ser::WritingError> {
|
|
write.write_i8(self.flags)?;
|
|
write.write_f32_be(self.flying_speed)?;
|
|
write.write_f32_be(self.field_of_view)?;
|
|
Ok(())
|
|
}
|
|
}
|