fix: 2 bedrock packets

This commit is contained in:
Alexander Medvedev committed 2026-06-27 17:44:55 +02:00
1 parent 1dbfb75ecc
commit 25048f5a6c
4 files changed
+62 -9

No files matched your search

@@ -0,0 +1,36 @@
use crate::{
bedrock::network_item::{FullContainerName, NetworkItemStackDescriptor},
codec::var_uint::VarUInt,
serial::PacketWrite,
};
use pumpkin_macros::packet;
use std::io::{Error, Write};
#[packet(50)]
pub struct CInventorySlot {
pub window_id: VarUInt,
pub inventory_slot: VarUInt,
pub container_name: Option<FullContainerName>,
pub storage: Option<NetworkItemStackDescriptor>,
pub item: NetworkItemStackDescriptor,
}
impl PacketWrite for CInventorySlot {
fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
self.window_id.write(writer)?;
self.inventory_slot.write(writer)?;
self.container_name.is_some().write(writer)?;
if let Some(container_name) = &self.container_name {
container_name.write(writer)?;
}
self.storage.is_some().write(writer)?;
if let Some(storage) = &self.storage {
storage.write(writer)?;
}
self.item.write(writer)?;
Ok(())
}
}
@@ -12,6 +12,7 @@ pub mod disconnect_player;
pub mod gamerules_changed; pub mod gamerules_changed;
pub mod handshake; pub mod handshake;
pub mod inventory_content; pub mod inventory_content;
pub mod inventory_slot;
pub mod item_registry; pub mod item_registry;
pub mod item_stack_response; pub mod item_stack_response;
pub mod level_chunk; pub mod level_chunk;
@@ -57,6 +58,7 @@ pub use disconnect_player::*;
pub use gamerules_changed::*; pub use gamerules_changed::*;
pub use handshake::*; pub use handshake::*;
pub use inventory_content::*; pub use inventory_content::*;
pub use inventory_slot::*;
pub use item_registry::*; pub use item_registry::*;
pub use item_stack_response::*; pub use item_stack_response::*;
pub use level_chunk::*; pub use level_chunk::*;
+10 -5
View File
@@ -146,14 +146,16 @@ pub struct ItemStackWrapper {
impl PacketWrite for ItemStackWrapper { impl PacketWrite for ItemStackWrapper {
fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> { fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
self.id.write(writer)?; VarInt(self.id as i32).write(writer)?;
if self.id != 0 { if self.id != 0 {
self.stack_size.write(writer)?; self.stack_size.write(writer)?;
self.aux_value.write(writer)?; self.aux_value.write(writer)?;
self.net_id.is_some().write(writer)?; self.net_id.is_some().write(writer)?;
if let Some(id) = self.net_id { if let Some(id) = self.net_id {
VarUInt(0).write(writer)?; // variant
VarInt(id.get()).write(writer)?; VarInt(id.get()).write(writer)?;
} }
@@ -171,10 +173,14 @@ impl PacketWrite for ItemStackWrapper {
} }
(self.place_on_blocks.len() as u32).write(&mut buf)?; (self.place_on_blocks.len() as u32).write(&mut buf)?;
self.place_on_blocks.write(&mut buf)?; for block in &self.place_on_blocks {
block.write(&mut buf)?;
}
(self.destroy_blocks.len() as u32).write(&mut buf)?; (self.destroy_blocks.len() as u32).write(&mut buf)?;
self.destroy_blocks.write(&mut buf)?; for block in &self.destroy_blocks {
block.write(&mut buf)?;
}
if self.id == BedrockItem::SHIELD.id { if self.id == BedrockItem::SHIELD.id {
self.shield_blocking_tick.write(&mut buf)?; self.shield_blocking_tick.write(&mut buf)?;
@@ -198,7 +204,6 @@ impl PacketRead for ItemStackWrapper {
let has_net_id = bool::read(buf)?; let has_net_id = bool::read(buf)?;
let net_id = if has_net_id { let net_id = if has_net_id {
let _variant = VarUInt::read(buf)?;
let stack_id = VarInt::read(buf)?; let stack_id = VarInt::read(buf)?;
NonZeroI32::new(stack_id.0) NonZeroI32::new(stack_id.0)
} else { } else {
+14 -4
View File
@@ -3414,11 +3414,20 @@ impl World {
} }
} }
if !ids_to_remove.is_empty() { if !ids_to_remove.is_empty() {
player match player.client.as_ref() {
.client crate::net::ClientPlatform::Java(java) => {
.enqueue_packet(&CRemoveEntities::new(&ids_to_remove)) java.enqueue_packet(&CRemoveEntities::new(&ids_to_remove))
.await; .await;
} }
crate::net::ClientPlatform::Bedrock(bedrock) => {
for id in &ids_to_remove {
bedrock
.enqueue_packet(&CRemoveActor::new(VarLong(id.0 as i64)))
.await;
}
}
}
}
continue 'main; continue 'main;
} }
@@ -3979,9 +3988,10 @@ impl World {
}); });
let chunk_pos = base_entity.chunk_pos.load(); let chunk_pos = base_entity.chunk_pos.load();
self.broadcast_to_chunk( self.broadcast_to_chunk_editioned_sync(
chunk_pos, chunk_pos,
&CRemoveEntities::new(&[base_entity.entity_id.into()]), &CRemoveEntities::new(&[base_entity.entity_id.into()]),
&CRemoveActor::new(VarLong(base_entity.entity_id as i64)),
); );
self.remove_entity_data(base_entity).await; self.remove_entity_data(base_entity).await;