Skip to content

Commit 74e58ca

Browse files
committed
Handle player packet id 0x23
1 parent b7ac8ad commit 74e58ca

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ Cargo.lock
7777

7878
# === PROJECT SPECIFIC ===
7979
# mc decompiled source
80-
mc-source-code/DecompilerMC/
81-
mc-source-code/src/
82-
mc-source-code/target/
80+
mc-source-code/
8381

8482
plugins/*
8583
world/*

pumpkin-protocol/src/server/play/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod s_confirm_teleport;
77
mod s_interact;
88
mod s_keep_alive;
99
mod s_ping_request;
10+
mod s_player_abilities;
1011
mod s_player_action;
1112
mod s_player_command;
1213
mod s_player_ground;
@@ -28,6 +29,7 @@ pub use s_confirm_teleport::*;
2829
pub use s_interact::*;
2930
pub use s_keep_alive::*;
3031
pub use s_ping_request::*;
32+
pub use s_player_abilities::*;
3133
pub use s_player_action::*;
3234
pub use s_player_command::*;
3335
pub use s_player_ground::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use pumpkin_macros::packet;
2+
use serde::Deserialize;
3+
4+
//The vanilla client sends this packet when the player starts/stops flying. Bitmask 0x02 is set when the player is flying.
5+
6+
#[derive(Deserialize)]
7+
#[packet(0x23)]
8+
pub struct SPlayerAbilities {
9+
pub flags: i8,
10+
}

pumpkin/src/client/player_packet.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ use pumpkin_core::{
1515
};
1616
use pumpkin_entity::EntityId;
1717
use pumpkin_inventory::{InventoryError, WindowType};
18-
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem};
1918
use pumpkin_protocol::{
2019
client::play::{
2120
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
2221
CHeadRot, CHurtAnimation, CPingResponse, CPlayerChatMessage, CUpdateEntityPos,
2322
CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent, FilterType,
2423
},
2524
server::play::{
26-
Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport,
27-
SInteract, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition,
28-
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm,
29-
SUseItemOn, Status,
25+
Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SCloseContainer,
26+
SConfirmTeleport, SInteract, SPlayPingRequest, SPlayerAbilities, SPlayerAction,
27+
SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
28+
SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItem, SUseItemOn, Status,
3029
},
3130
};
3231
use pumpkin_world::block::{BlockFace, BlockState};
@@ -468,6 +467,7 @@ impl Player {
468467
None => self.kick(TextComponent::text("Invalid action type")).await,
469468
}
470469
}
470+
471471
pub async fn handle_player_action(&self, player_action: SPlayerAction) {
472472
match Status::from_i32(player_action.status.0) {
473473
Some(status) => match status {
@@ -541,6 +541,13 @@ impl Player {
541541
}
542542
}
543543

544+
pub async fn handle_player_abilities(&self, player_abilities: SPlayerAbilities) {
545+
let mut abilities = self.abilities.lock().await;
546+
547+
// Set the flying ability
548+
abilities.flying = player_abilities.flags & 0x02 != 0 && abilities.allow_flying;
549+
}
550+
544551
pub async fn handle_play_ping_request(&self, request: SPlayPingRequest) {
545552
self.client
546553
.send_packet(&CPingResponse::new(request.payload))

pumpkin/src/entity/player.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ use pumpkin_protocol::{
2020
CSyncPlayerPosition, CSystemChatMessage, GameEvent, PlayerAction,
2121
},
2222
server::play::{
23-
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport,
24-
SInteract, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition,
25-
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround,
26-
SSwingArm, SUseItem, SUseItemOn,
23+
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport, SInteract, SPlayPingRequest, SPlayerAbilities, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItem, SUseItemOn
2724
},
2825
RawPacket, ServerPacket, VarInt,
2926
};
@@ -73,7 +70,7 @@ pub struct Player {
7370
/// This field represents the various abilities that the player possesses, such as flight, invulnerability, and other special effects.
7471
///
7572
/// **Note:** When the `abilities` field is updated, the server should send a `send_abilities_update` packet to the client to notify them of the changes.
76-
pub abilities: PlayerAbilities,
73+
pub abilities: Mutex<PlayerAbilities>,
7774
/// The player's last known position.
7875
///
7976
/// This field is used to calculate the player's movement delta for network synchronization and other purposes.
@@ -129,7 +126,7 @@ impl Player {
129126
open_container: AtomicCell::new(None),
130127
carried_item: AtomicCell::new(None),
131128
teleport_id_count: AtomicI32::new(0),
132-
abilities: PlayerAbilities::default(),
129+
abilities: Mutex::new(PlayerAbilities::default()),
133130
gamemode: AtomicCell::new(gamemode),
134131
watched_section: AtomicCell::new(Vector3::new(0, 0, 0)),
135132
last_position: AtomicCell::new(Vector3::new(0.0, 0.0, 0.0)),
@@ -157,7 +154,7 @@ impl Player {
157154
/// Updates the current abilities the Player has
158155
pub async fn send_abilties_update(&mut self) {
159156
let mut b = 0i8;
160-
let abilities = &self.abilities;
157+
let abilities = &self.abilities.lock().await;
161158

162159
if abilities.invulnerable {
163160
b |= 1;
@@ -379,6 +376,11 @@ impl Player {
379376
.await;
380377
Ok(())
381378
}
379+
SPlayerAbilities::PACKET_ID => {
380+
self.handle_player_abilities(SPlayerAbilities::read(bytebuf)?)
381+
.await;
382+
Ok(())
383+
}
382384
SUseItemOn::PACKET_ID => {
383385
self.handle_use_item_on(SUseItemOn::read(bytebuf)?).await;
384386
Ok(())

0 commit comments

Comments
 (0)