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:
parent
589d2585b8
commit
5122097d0d
16
pumpkin-protocol/src/client/play/c_acknowledge_block.rs
Normal file
16
pumpkin-protocol/src/client/play/c_acknowledge_block.rs
Normal 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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
mod c_acknowledge_block;
|
||||||
mod c_actionbar;
|
mod c_actionbar;
|
||||||
mod c_block_destroy_stage;
|
mod c_block_destroy_stage;
|
||||||
mod c_block_update;
|
mod c_block_update;
|
||||||
@ -32,6 +33,7 @@ mod c_update_entity_rot;
|
|||||||
mod c_worldevent;
|
mod c_worldevent;
|
||||||
mod player_action;
|
mod player_action;
|
||||||
|
|
||||||
|
pub use c_acknowledge_block::*;
|
||||||
pub use c_actionbar::*;
|
pub use c_actionbar::*;
|
||||||
pub use c_block_destroy_stage::*;
|
pub use c_block_destroy_stage::*;
|
||||||
pub use c_block_update::*;
|
pub use c_block_update::*;
|
||||||
|
|||||||
@ -13,5 +13,5 @@ pub struct SUseItemOn {
|
|||||||
pub cursor_pos_y: f32,
|
pub cursor_pos_y: f32,
|
||||||
pub cursor_pos_z: f32,
|
pub cursor_pos_z: f32,
|
||||||
pub inside_block: bool,
|
pub inside_block: bool,
|
||||||
pub sequene: VarInt,
|
pub sequence: VarInt,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,9 @@ use num_traits::FromPrimitive;
|
|||||||
use pumpkin_entity::EntityId;
|
use pumpkin_entity::EntityId;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::play::{
|
client::play::{
|
||||||
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
|
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
|
||||||
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent,
|
CHeadRot, CHurtAnimation, CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot,
|
||||||
FilterType,
|
CUpdateEntityRot, CWorldEvent, FilterType,
|
||||||
},
|
},
|
||||||
position::WorldPosition,
|
position::WorldPosition,
|
||||||
server::play::{
|
server::play::{
|
||||||
@ -319,6 +319,7 @@ impl Client {
|
|||||||
pub fn handle_player_action(&mut self, server: &mut Server, player_action: SPlayerAction) {
|
pub fn handle_player_action(&mut self, server: &mut Server, player_action: SPlayerAction) {
|
||||||
match Status::from_i32(player_action.status.0).unwrap() {
|
match Status::from_i32(player_action.status.0).unwrap() {
|
||||||
Status::StartedDigging => {
|
Status::StartedDigging => {
|
||||||
|
// TODO: do validation
|
||||||
let player = self.player.as_mut().unwrap();
|
let player = self.player.as_mut().unwrap();
|
||||||
// TODO: Config
|
// TODO: Config
|
||||||
if player.gamemode == GameMode::Creative {
|
if player.gamemode == GameMode::Creative {
|
||||||
@ -335,12 +336,15 @@ impl Client {
|
|||||||
player.current_block_destroy_stage = 0;
|
player.current_block_destroy_stage = 0;
|
||||||
}
|
}
|
||||||
Status::FinishedDigging => {
|
Status::FinishedDigging => {
|
||||||
|
// TODO: do validation
|
||||||
let location = player_action.location;
|
let location = player_action.location;
|
||||||
// Block break & block break sound
|
// Block break & block break sound
|
||||||
// TODO: currently this is always dirt replace it
|
// TODO: currently this is always dirt replace it
|
||||||
server.broadcast_packet(self, &CWorldEvent::new(2001, &location, 11, false));
|
server.broadcast_packet(self, &CWorldEvent::new(2001, &location, 11, false));
|
||||||
// AIR
|
// AIR
|
||||||
server.broadcast_packet(self, &CBlockUpdate::new(location, 0.into()));
|
server.broadcast_packet(self, &CBlockUpdate::new(location, 0.into()));
|
||||||
|
// TODO: Send this every tick
|
||||||
|
self.send_packet(&CAcknowledgeBlockChange::new(player_action.sequence));
|
||||||
}
|
}
|
||||||
Status::DropItemStack => {
|
Status::DropItemStack => {
|
||||||
dbg!("todo");
|
dbg!("todo");
|
||||||
@ -358,6 +362,8 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
|
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 location = use_item_on.location;
|
||||||
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
|
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
|
||||||
let location = WorldPosition(location.0 + face.to_offset());
|
let location = WorldPosition(location.0 + face.to_offset());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user