Acknowledge only the latest dug block sequence

This commit is contained in:
Ryan 2022-09-19 19:19:20 -07:00
parent 4574e18d49
commit d25f3674fb

View file

@ -222,7 +222,7 @@ pub struct Client<C: Config> {
new_game_mode: GameMode, new_game_mode: GameMode,
old_game_mode: GameMode, old_game_mode: GameMode,
settings: Option<Settings>, settings: Option<Settings>,
dug_blocks: Vec<i32>, dug_block_sequence: i32,
/// Should be sent after login packet. /// Should be sent after login packet.
msgs_to_send: Vec<Text>, msgs_to_send: Vec<Text>,
bar_to_send: Option<Text>, bar_to_send: Option<Text>,
@ -293,7 +293,7 @@ impl<C: Config> Client<C> {
new_game_mode: GameMode::Survival, new_game_mode: GameMode::Survival,
old_game_mode: GameMode::Survival, old_game_mode: GameMode::Survival,
settings: None, settings: None,
dug_blocks: Vec::new(), dug_block_sequence: 0,
msgs_to_send: Vec::new(), msgs_to_send: Vec::new(),
bar_to_send: None, bar_to_send: None,
resource_pack_to_send: None, resource_pack_to_send: None,
@ -911,22 +911,22 @@ impl<C: Config> Client<C> {
C2sPlayPacket::PlayerAbilitiesC2s(_) => {} C2sPlayPacket::PlayerAbilitiesC2s(_) => {}
C2sPlayPacket::PlayerAction(p) => { C2sPlayPacket::PlayerAction(p) => {
if p.sequence.0 != 0 { if p.sequence.0 != 0 {
self.dug_blocks.push(p.sequence.0); self.dug_block_sequence = p.sequence.0;
} }
self.events.push_back(match p.status { self.events.push_back(match p.status {
play::DiggingStatus::StartedDigging => ClientEvent::Digging { play::DiggingStatus::StartedDigging => ClientEvent::Digging {
status: event::DiggingStatus::Start, status: DiggingStatus::Start,
position: p.location, position: p.location,
face: p.face, face: p.face,
}, },
play::DiggingStatus::CancelledDigging => ClientEvent::Digging { play::DiggingStatus::CancelledDigging => ClientEvent::Digging {
status: event::DiggingStatus::Cancel, status: DiggingStatus::Cancel,
position: p.location, position: p.location,
face: p.face, face: p.face,
}, },
play::DiggingStatus::FinishedDigging => ClientEvent::Digging { play::DiggingStatus::FinishedDigging => ClientEvent::Digging {
status: event::DiggingStatus::Finish, status: DiggingStatus::Finish,
position: p.location, position: p.location,
face: p.face, face: p.face,
}, },
@ -1279,13 +1279,14 @@ impl<C: Config> Client<C> {
} }
// Acknowledge broken blocks. // Acknowledge broken blocks.
for seq in self.dug_blocks.drain(..) { if self.dug_block_sequence != 0 {
send_packet( send_packet(
&mut self.send, &mut self.send,
AcknowledgeBlockChange { AcknowledgeBlockChange {
sequence: VarInt(seq), sequence: VarInt(self.dug_block_sequence),
}, },
) );
self.dug_block_sequence = 0;
} }
// Teleport the player. // Teleport the player.