steel_protocol/packets/game/
c_player_abilities.rs1use steel_macros::{ClientPacket, WriteTo};
2use steel_registry::packets::play::C_PLAYER_ABILITIES;
3
4pub mod ability_flags {
7 pub const INVULNERABLE: u8 = 0x01;
8 pub const FLYING: u8 = 0x02;
9 pub const MAY_FLY: u8 = 0x04;
10 pub const INSTABUILD: u8 = 0x08;
11}
12
13#[derive(ClientPacket, WriteTo, Clone, Debug)]
16#[packet_id(Play = C_PLAYER_ABILITIES)]
17pub struct CPlayerAbilities {
18 pub flags: u8,
20 pub flying_speed: f32,
22 pub walking_speed: f32,
24}
25
26impl CPlayerAbilities {
27 pub const DEFAULT_FLYING_SPEED: f32 = 0.05;
29 pub const DEFAULT_WALKING_SPEED: f32 = 0.1;
31
32 #[must_use]
34 pub const fn survival() -> Self {
35 Self {
36 flags: 0,
37 flying_speed: Self::DEFAULT_FLYING_SPEED,
38 walking_speed: Self::DEFAULT_WALKING_SPEED,
39 }
40 }
41
42 #[must_use]
44 pub const fn creative() -> Self {
45 Self {
46 flags: ability_flags::INVULNERABLE | ability_flags::MAY_FLY | ability_flags::INSTABUILD,
47 flying_speed: Self::DEFAULT_FLYING_SPEED,
48 walking_speed: Self::DEFAULT_WALKING_SPEED,
49 }
50 }
51
52 #[must_use]
54 pub const fn adventure() -> Self {
55 Self {
56 flags: 0,
57 flying_speed: Self::DEFAULT_FLYING_SPEED,
58 walking_speed: Self::DEFAULT_WALKING_SPEED,
59 }
60 }
61
62 #[must_use]
64 pub const fn spectator() -> Self {
65 Self {
66 flags: ability_flags::INVULNERABLE | ability_flags::MAY_FLY | ability_flags::FLYING,
68 flying_speed: Self::DEFAULT_FLYING_SPEED,
69 walking_speed: Self::DEFAULT_WALKING_SPEED,
70 }
71 }
72}