Add Clientbound Acknowledge Block Change

Acknowledges a user-initiated block change. After receiving this packet, the client will display the block state sent by the server instead of the one predicted by the client.
This commit is contained in:
Snowiiii
2024-08-20 17:33:03 +02:00
parent 589d2585b8
commit 5122097d0d
4 changed files with 28 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
use pumpkin_macros::packet;
use serde::Serialize;
use crate::VarInt;
#[derive(Serialize)]
#[packet(0x05)]
pub struct CAcknowledgeBlockChange {
sequence_id: VarInt,
}
impl CAcknowledgeBlockChange {
pub fn new(sequence_id: VarInt) -> Self {
Self { sequence_id }
}
}

View File

@@ -1,3 +1,4 @@
mod c_acknowledge_block;
mod c_actionbar;
mod c_block_destroy_stage;
mod c_block_update;
@@ -32,6 +33,7 @@ mod c_update_entity_rot;
mod c_worldevent;
mod player_action;
pub use c_acknowledge_block::*;
pub use c_actionbar::*;
pub use c_block_destroy_stage::*;
pub use c_block_update::*;

View File

@@ -13,5 +13,5 @@ pub struct SUseItemOn {
pub cursor_pos_y: f32,
pub cursor_pos_z: f32,
pub inside_block: bool,
pub sequene: VarInt,
pub sequence: VarInt,
}

View File

@@ -10,9 +10,9 @@ use num_traits::FromPrimitive;
use pumpkin_entity::EntityId;
use pumpkin_protocol::{
client::play::{
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent,
FilterType,
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
CHeadRot, CHurtAnimation, CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot,
CUpdateEntityRot, CWorldEvent, FilterType,
},
position::WorldPosition,
server::play::{
@@ -319,6 +319,7 @@ impl Client {
pub fn handle_player_action(&mut self, server: &mut Server, player_action: SPlayerAction) {
match Status::from_i32(player_action.status.0).unwrap() {
Status::StartedDigging => {
// TODO: do validation
let player = self.player.as_mut().unwrap();
// TODO: Config
if player.gamemode == GameMode::Creative {
@@ -335,12 +336,15 @@ impl Client {
player.current_block_destroy_stage = 0;
}
Status::FinishedDigging => {
// TODO: do validation
let location = player_action.location;
// Block break & block break sound
// TODO: currently this is always dirt replace it
server.broadcast_packet(self, &CWorldEvent::new(2001, &location, 11, false));
// AIR
server.broadcast_packet(self, &CBlockUpdate::new(location, 0.into()));
// TODO: Send this every tick
self.send_packet(&CAcknowledgeBlockChange::new(player_action.sequence));
}
Status::DropItemStack => {
dbg!("todo");
@@ -358,6 +362,8 @@ impl Client {
}
pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
self.send_packet(&CAcknowledgeBlockChange::new(use_item_on.sequence));
let location = use_item_on.location;
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
let location = WorldPosition(location.0 + face.to_offset());