From 2a094dd4ae81452b9ca15ce8cc5614f2a5bf0a1c Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sat, 10 Aug 2024 02:03:53 +0800 Subject: [PATCH 1/5] ServerPlayerPostMovePositionPacket --- crates/proto/src/gamepacket.rs | 12 ++++++++++++ crates/proto/src/packets/mod.rs | 1 + .../server_player_post_move_position_packet.rs | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 crates/proto/src/packets/server_player_post_move_position_packet.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index d77590fe..f1d303c5 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -29,6 +29,7 @@ use crate::packets::request_chunk_radius::RequestChunkRadiusPacket; use crate::packets::resource_packs_info::ResourcePacksInfoPacket; use crate::packets::resource_packs_response::ResourcePacksResponsePacket; use crate::packets::resource_packs_stack::ResourcePacksStackPacket; +use crate::packets::server_player_post_move_position_packet::ServerPlayerPostMovePositionPacket; use crate::packets::server_settings_request::ServerSettingsRequestPacket; use crate::packets::server_settings_response::ServerSettingsResponsePacket; use crate::packets::set_local_player_as_initialized::SetLocalPlayerAsInitializedPacket; @@ -58,6 +59,7 @@ pub enum GamePacket { AddEntity(AddActorPacket), RemoveEntity(), AddItemEntity(), + ServerPlayerPostMovePositionPacket(ServerPlayerPostMovePositionPacket), TakeItemEntity(), MoveEntity(), MovePlayer(MovePlayerPacket), @@ -211,6 +213,7 @@ impl GamePacket { const AddEntityID: u16 = 13; const RemoveEntityID: u16 = 14; const AddItemEntityID: u16 = 15; + const ServerPlayerPostMovePositionPacketID: u16 = 16; const TakeItemEntityID: u16 = 17; const MoveEntityID: u16 = 18; const MovePlayerID: u16 = 19; @@ -449,6 +452,9 @@ impl GamePacket { GamePacket::AddItemEntity() => { unimplemented!() } + GamePacket::ServerPlayerPostMovePositionPacket(pk) => { + ser_packet!(stream, GamePacket::ServerPlayerPostMovePositionPacketID, pk) + } GamePacket::TakeItemEntity() => { unimplemented!() } @@ -924,6 +930,12 @@ impl GamePacket { GamePacket::AddItemEntityID => { unimplemented!() } + GamePacket::ServerPlayerPostMovePositionPacketID => { + GamePacket::ServerPlayerPostMovePositionPacket(de_packet!( + stream, + ServerPlayerPostMovePositionPacket + )) + } GamePacket::TakeItemEntityID => { unimplemented!() } diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index cd8321ab..55e9bc39 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -24,6 +24,7 @@ pub mod request_chunk_radius; pub mod resource_packs_info; pub mod resource_packs_response; pub mod resource_packs_stack; +pub mod server_player_post_move_position_packet; pub mod server_settings_request; pub mod server_settings_response; pub mod set_local_player_as_initialized; diff --git a/crates/proto/src/packets/server_player_post_move_position_packet.rs b/crates/proto/src/packets/server_player_post_move_position_packet.rs new file mode 100644 index 00000000..692d7c93 --- /dev/null +++ b/crates/proto/src/packets/server_player_post_move_position_packet.rs @@ -0,0 +1,7 @@ +use bedrockrs_core::{int::LE, Vec3}; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct ServerPlayerPostMovePositionPacket { + pos: Vec3>, +} From 9e1ebfb23a1f93c5edeba6b17aab8d4c01e20831 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sat, 10 Aug 2024 02:27:42 +0800 Subject: [PATCH 2/5] RemoveEntityPacket --- crates/proto/src/gamepacket.rs | 9 +++++---- crates/proto/src/packets/mod.rs | 1 + crates/proto/src/packets/remove_actor_packet.rs | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 crates/proto/src/packets/remove_actor_packet.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index f1d303c5..e1370b35 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -25,6 +25,7 @@ use crate::packets::play_status::PlayStatusPacket; use crate::packets::player_action::PlayerActionPacket; use crate::packets::player_auth_input::PlayerAuthInputPacket; use crate::packets::player_move::MovePlayerPacket; +use crate::packets::remove_actor_packet::RemoveEntityPacket; use crate::packets::request_chunk_radius::RequestChunkRadiusPacket; use crate::packets::resource_packs_info::ResourcePacksInfoPacket; use crate::packets::resource_packs_response::ResourcePacksResponsePacket; @@ -57,7 +58,7 @@ pub enum GamePacket { StartGame(StartGamePacket), AddPlayer(), AddEntity(AddActorPacket), - RemoveEntity(), + RemoveEntity(RemoveEntityPacket), AddItemEntity(), ServerPlayerPostMovePositionPacket(ServerPlayerPostMovePositionPacket), TakeItemEntity(), @@ -446,8 +447,8 @@ impl GamePacket { GamePacket::AddEntity(pk) => { ser_packet!(stream, GamePacket::AddEntityID, pk) } - GamePacket::RemoveEntity() => { - unimplemented!() + GamePacket::RemoveEntity(pk) => { + ser_packet!(stream, GamePacket::RemoveEntityID, pk) } GamePacket::AddItemEntity() => { unimplemented!() @@ -925,7 +926,7 @@ impl GamePacket { } GamePacket::AddEntityID => GamePacket::AddEntity(de_packet!(stream, AddActorPacket)), GamePacket::RemoveEntityID => { - unimplemented!() + GamePacket::RemoveEntity(de_packet!(stream, RemoveActorPacket)) } GamePacket::AddItemEntityID => { unimplemented!() diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index 55e9bc39..a1ee7085 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -20,6 +20,7 @@ pub mod play_status; pub mod player_action; pub mod player_auth_input; pub mod player_move; +pub mod remove_actor_packet; pub mod request_chunk_radius; pub mod resource_packs_info; pub mod resource_packs_response; diff --git a/crates/proto/src/packets/remove_actor_packet.rs b/crates/proto/src/packets/remove_actor_packet.rs new file mode 100644 index 00000000..7c1212be --- /dev/null +++ b/crates/proto/src/packets/remove_actor_packet.rs @@ -0,0 +1,7 @@ +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::actor_unique_id::ActorUniqueID; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct RemoveEntityPacket { + pub target_actor_id: ActorUniqueID, +} From 3fbbed24062b5020ffc66fe9684b8f3c201d2c96 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sat, 10 Aug 2024 02:39:23 +0800 Subject: [PATCH 3/5] fix RemoveEntityPacket to RemoveActorPacket --- crates/proto/src/gamepacket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index e1370b35..00f21bc3 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -926,7 +926,7 @@ impl GamePacket { } GamePacket::AddEntityID => GamePacket::AddEntity(de_packet!(stream, AddActorPacket)), GamePacket::RemoveEntityID => { - GamePacket::RemoveEntity(de_packet!(stream, RemoveActorPacket)) + GamePacket::RemoveEntity(de_packet!(stream, RemoveEntityPacket)) } GamePacket::AddItemEntityID => { unimplemented!() From 4ede39844793c81a774eb113c6a7bd3d5e337106 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sat, 10 Aug 2024 02:49:21 +0800 Subject: [PATCH 4/5] add CameraPacket --- crates/proto/src/gamepacket.rs | 11 +++++------ crates/proto/src/packets/camera_packet.rs | 8 ++++++++ crates/proto/src/packets/mod.rs | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 crates/proto/src/packets/camera_packet.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 00f21bc3..390e8214 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use crate::packets::add_actor_packet::AddActorPacket; use crate::packets::animate::AnimatePacket; +use crate::packets::camera_packet::CameraPacket; use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket; use crate::packets::client_cache_status::ClientCacheStatusPacket; use crate::packets::command_request_packet::CommandRequestPacket; @@ -116,7 +117,7 @@ pub enum GamePacket { ChunkRadiusUpdate(ChunkRadiusUpdatedPacket), ItemFrameDropItem(), GameRulesChanged(), - Camera(), + Camera(CameraPacket), BossEvent(), ShowCredits(), AvailableCommands(), @@ -621,8 +622,8 @@ impl GamePacket { GamePacket::GameRulesChanged() => { unimplemented!() } - GamePacket::Camera() => { - unimplemented!() + GamePacket::Camera(pk) => { + ser_packet!(stream, GamePacket::CameraID, pk) } GamePacket::BossEvent() => { unimplemented!() @@ -1098,9 +1099,7 @@ impl GamePacket { GamePacket::GameRulesChangedID => { unimplemented!() } - GamePacket::CameraID => { - unimplemented!() - } + GamePacket::CameraID => GamePacket::Camera(de_packet!(stream, CameraPacket)), GamePacket::BossEventID => { unimplemented!() } diff --git a/crates/proto/src/packets/camera_packet.rs b/crates/proto/src/packets/camera_packet.rs new file mode 100644 index 00000000..7d16ccea --- /dev/null +++ b/crates/proto/src/packets/camera_packet.rs @@ -0,0 +1,8 @@ +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::actor_unique_id::ActorUniqueID; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct CameraPacket { + pub camera_id: ActorUniqueID, + pub target_player_id: ActorUniqueID, +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index a1ee7085..bcc437cf 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -1,5 +1,6 @@ pub mod add_actor_packet; pub mod animate; +pub mod camera_packet; pub mod chunk_radius_updated; pub mod client_cache_status; pub mod command_request_packet; From 014f81eefc0020c16a5204bcd81b52697fa1c947 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 12 Aug 2024 01:32:15 +0800 Subject: [PATCH 5/5] add datapacket: AddPaintingPacket ContainerOpenPacket DebugInfoPacket InventoryContentPacket MobEquipmentPacket PlayerHotbarPacket SetTimePacket add datapacket type: ContainerID ItemStackNetIdVariant NetworkItemStackDescriptor Valid --- crates/proto/src/gamepacket.rs | 65 +++++++++++-------- .../proto/src/packets/add_painting_packet.rs | 15 +++++ .../src/packets/container_open_packet.rs | 13 ++++ crates/proto/src/packets/debug_info_packet.rs | 8 +++ .../src/packets/inventory_content_packet.rs | 11 ++++ .../proto/src/packets/mob_equipment_packet.rs | 13 ++++ crates/proto/src/packets/mod.rs | 7 ++ .../proto/src/packets/player_hotbar_packet.rs | 26 ++++++++ crates/proto/src/packets/set_time_packet.rs | 7 ++ crates/proto/src/types/container_id.rs | 33 ++++++++++ .../src/types/item_stack_net_id_variant.rs | 6 ++ crates/proto/src/types/mod.rs | 4 ++ .../types/network_item_stack_descriptor.rs | 47 ++++++++++++++ crates/proto/src/types/valid.rs | 15 +++++ 14 files changed, 244 insertions(+), 26 deletions(-) create mode 100644 crates/proto/src/packets/add_painting_packet.rs create mode 100644 crates/proto/src/packets/container_open_packet.rs create mode 100644 crates/proto/src/packets/debug_info_packet.rs create mode 100644 crates/proto/src/packets/inventory_content_packet.rs create mode 100644 crates/proto/src/packets/mob_equipment_packet.rs create mode 100644 crates/proto/src/packets/player_hotbar_packet.rs create mode 100644 crates/proto/src/packets/set_time_packet.rs create mode 100644 crates/proto/src/types/container_id.rs create mode 100644 crates/proto/src/types/item_stack_net_id_variant.rs create mode 100644 crates/proto/src/types/network_item_stack_descriptor.rs create mode 100644 crates/proto/src/types/valid.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 390e8214..f4b9895f 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -4,19 +4,24 @@ use std::io::{Cursor, Write}; use std::sync::Arc; use crate::packets::add_actor_packet::AddActorPacket; +use crate::packets::add_painting_packet::AddPaintingPacket; use crate::packets::animate::AnimatePacket; use crate::packets::camera_packet::CameraPacket; use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket; use crate::packets::client_cache_status::ClientCacheStatusPacket; use crate::packets::command_request_packet::CommandRequestPacket; use crate::packets::container_close_packet::ContainerClosePacket; +use crate::packets::container_open_packet::ContainerOpenPacket; use crate::packets::correct_player_move_prediction_packet::CorrectPlayerMovePredictionPacket; +use crate::packets::debug_info_packet::DebugInfoPacket; use crate::packets::disconnect::DisconnectPacket; use crate::packets::emote_list::EmoteListPacket; use crate::packets::handshake_server_to_client::HandshakeServerToClientPacket; use crate::packets::interact::InteractPacket; +use crate::packets::inventory_content_packet::InventoryContentPacket; use crate::packets::level_chunk::LevelChunkPacket; use crate::packets::login::LoginPacket; +use crate::packets::mob_equipment_packet::MobEquipmentPacket; use crate::packets::modal_form_request::ModalFormRequestPacket; use crate::packets::modal_form_response::ModalFormResponsePacket; use crate::packets::network_settings::NetworkSettingsPacket; @@ -25,6 +30,7 @@ use crate::packets::packet_violation_warning::PacketViolationWarningPacket; use crate::packets::play_status::PlayStatusPacket; use crate::packets::player_action::PlayerActionPacket; use crate::packets::player_auth_input::PlayerAuthInputPacket; +use crate::packets::player_hotbar_packet::PlayerHotbarPacket; use crate::packets::player_move::MovePlayerPacket; use crate::packets::remove_actor_packet::RemoveEntityPacket; use crate::packets::request_chunk_radius::RequestChunkRadiusPacket; @@ -35,6 +41,7 @@ use crate::packets::server_player_post_move_position_packet::ServerPlayerPostMov use crate::packets::server_settings_request::ServerSettingsRequestPacket; use crate::packets::server_settings_response::ServerSettingsResponsePacket; use crate::packets::set_local_player_as_initialized::SetLocalPlayerAsInitializedPacket; +use crate::packets::set_time_packet::SetTimePacket; use crate::packets::set_title_packet::SetTitlePacket; use crate::packets::start_game::StartGamePacket; use crate::packets::text_message::TextMessagePacket; @@ -55,7 +62,7 @@ pub enum GamePacket { ResourcePackStack(ResourcePacksStackPacket), ResourcePackClientResponse(ResourcePacksResponsePacket), TextMessage(TextMessagePacket), - SetTime(), + SetTime(SetTimePacket), StartGame(StartGamePacket), AddPlayer(), AddEntity(AddActorPacket), @@ -67,7 +74,7 @@ pub enum GamePacket { MovePlayer(MovePlayerPacket), RiderJump(), UpdateBlock(), - AddPainting(), + AddPainting(AddPaintingPacket), TickSync(), LevelSoundEventOld(), LevelEvent(), @@ -76,7 +83,7 @@ pub enum GamePacket { MobEffect(), UpdateAttributes(), InventoryTransaction(), - MobEquipment(), + MobEquipment(MobEquipmentPacket), MobArmorEquipment(), Interact(InteractPacket), BlockPickRequest(), @@ -90,10 +97,10 @@ pub enum GamePacket { SetSpawnPosition(), Animate(AnimatePacket), Respawn(), - ContainerOpen(), + ContainerOpen(ContainerOpenPacket), ContainerClose(ContainerClosePacket), - PlayerHotbar(), - InventoryContent(), + PlayerHotbar(PlayerHotbarPacket), + InventoryContent(InventoryContentPacket), InventorySlot(), ContainerSetData(), CraftingData(), @@ -186,6 +193,7 @@ pub enum GamePacket { ItemStackResponse(), UpdatePlayerGameType(), EmoteList(EmoteListPacket), + DebugInfoPacket(DebugInfoPacket), PacketViolationWarning(PacketViolationWarningPacket), CorrectPlayerMovePredictionPacket(CorrectPlayerMovePredictionPacket), ItemComponent(), @@ -340,6 +348,7 @@ impl GamePacket { const ItemStackResponseID: u16 = 148; const UpdatePlayerGameTypeID: u16 = 151; const EmoteListID: u16 = 152; + const DebugInfoPacketID: u16 = 155; const PacketViolationWarningID: u16 = 156; const CorrectPlayerMovePredictionPacketID: u16 = 161; const ItemComponentID: u16 = 162; @@ -436,8 +445,8 @@ impl GamePacket { GamePacket::TextMessage(pk) => { ser_packet!(stream, GamePacket::TextMessageID, pk) } - GamePacket::SetTime() => { - unimplemented!() + GamePacket::SetTime(pk) => { + ser_packet!(stream, GamePacket::SetTimeID, pk) } GamePacket::StartGame(pk) => { ser_packet!(stream, GamePacket::StartGameID, pk) @@ -472,8 +481,8 @@ impl GamePacket { GamePacket::UpdateBlock() => { unimplemented!() } - GamePacket::AddPainting() => { - unimplemented!() + GamePacket::AddPainting(pk) => { + ser_packet!(stream, GamePacket::AddPaintingID, pk) } GamePacket::TickSync() => { unimplemented!() @@ -499,8 +508,8 @@ impl GamePacket { GamePacket::InventoryTransaction() => { unimplemented!() } - GamePacket::MobEquipment() => { - unimplemented!() + GamePacket::MobEquipment(pk) => { + ser_packet!(stream, GamePacket::MobEquipmentID, pk) } GamePacket::MobArmorEquipment() => { unimplemented!() @@ -541,17 +550,17 @@ impl GamePacket { GamePacket::Respawn() => { unimplemented!() } - GamePacket::ContainerOpen() => { - unimplemented!() + GamePacket::ContainerOpen(pk) => { + ser_packet!(stream, GamePacket::ContainerOpenID, pk) } GamePacket::ContainerClose(pk) => { ser_packet!(stream, GamePacket::ContainerCloseID, pk) } - GamePacket::PlayerHotbar() => { - unimplemented!() + GamePacket::PlayerHotbar(pk) => { + ser_packet!(stream, GamePacket::PlayerHotbarID, pk) } - GamePacket::InventoryContent() => { - unimplemented!() + GamePacket::InventoryContent(pk) => { + ser_packet!(stream, GamePacket::InventoryContentID, pk) } GamePacket::InventorySlot() => { unimplemented!() @@ -829,6 +838,9 @@ impl GamePacket { GamePacket::EmoteList(pk) => { ser_packet!(stream, GamePacket::EmoteListID, pk) } + GamePacket::DebugInfoPacket(pk) => { + ser_packet!(stream, GamePacket::DebugInfoPacketID, pk) + } GamePacket::PacketViolationWarning(pk) => { ser_packet!(stream, GamePacket::PacketViolationWarningID, pk) } @@ -918,9 +930,7 @@ impl GamePacket { GamePacket::TextMessageID => { GamePacket::TextMessage(de_packet!(stream, TextMessagePacket)) } - GamePacket::SetTimeID => { - unimplemented!() - } + GamePacket::SetTimeID => GamePacket::SetTime(de_packet!(stream, SetTimePacket)), GamePacket::StartGameID => GamePacket::StartGame(de_packet!(stream, StartGamePacket)), GamePacket::AddPlayerID => { unimplemented!() @@ -954,7 +964,7 @@ impl GamePacket { unimplemented!() } GamePacket::AddPaintingID => { - unimplemented!() + GamePacket::AddPainting(de_packet!(stream, AddPaintingPacket)) } GamePacket::TickSyncID => { unimplemented!() @@ -981,7 +991,7 @@ impl GamePacket { unimplemented!() } GamePacket::MobEquipmentID => { - unimplemented!() + GamePacket::MobEquipment(de_packet!(stream, MobEquipmentPacket)) } GamePacket::MobArmorEquipmentID => { unimplemented!() @@ -1019,16 +1029,16 @@ impl GamePacket { unimplemented!() } GamePacket::ContainerOpenID => { - unimplemented!() + GamePacket::ContainerOpen(de_packet!(stream, ContainerOpenPacket)) } GamePacket::ContainerCloseID => { GamePacket::ContainerClose(de_packet!(stream, ContainerClosePacket)) } GamePacket::PlayerHotbarID => { - unimplemented!() + GamePacket::PlayerHotbar(de_packet!(stream, PlayerHotbarPacket)) } GamePacket::InventoryContentID => { - unimplemented!() + GamePacket::InventoryContent(de_packet!(stream, InventoryContentPacket)) } GamePacket::InventorySlotID => { unimplemented!() @@ -1300,6 +1310,9 @@ impl GamePacket { unimplemented!() } GamePacket::EmoteListID => GamePacket::EmoteList(de_packet!(stream, EmoteListPacket)), + GamePacket::DebugInfoPacketID => { + GamePacket::DebugInfoPacket(de_packet!(stream, DebugInfoPacket)) + } GamePacket::PacketViolationWarningID => { GamePacket::PacketViolationWarning(de_packet!(stream, PacketViolationWarningPacket)) } diff --git a/crates/proto/src/packets/add_painting_packet.rs b/crates/proto/src/packets/add_painting_packet.rs new file mode 100644 index 00000000..8cb3e403 --- /dev/null +++ b/crates/proto/src/packets/add_painting_packet.rs @@ -0,0 +1,15 @@ +use bedrockrs_core::{ + int::{LE, VAR}, + Vec3, +}; +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct AddPaintingPacket { + pub target_actor_id: ActorUniqueID, + pub target_runtime_id: ActorRuntimeID, + pub position: Vec3>, + pub direction: VAR, + pub motif: String, +} diff --git a/crates/proto/src/packets/container_open_packet.rs b/crates/proto/src/packets/container_open_packet.rs new file mode 100644 index 00000000..28d30dd6 --- /dev/null +++ b/crates/proto/src/packets/container_open_packet.rs @@ -0,0 +1,13 @@ +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::actor_unique_id::ActorUniqueID; + +use crate::types::{ + container_id::ContainerID, container_type::ContainerType, network_block_pos::NetworkBlockPos, +}; +#[derive(ProtoCodec, Debug, Clone)] +pub struct ContainerOpenPacket { + pub container_id: ContainerID, + pub container_type: ContainerType, + pub position: NetworkBlockPos, + pub target_actor_id: ActorUniqueID, +} diff --git a/crates/proto/src/packets/debug_info_packet.rs b/crates/proto/src/packets/debug_info_packet.rs new file mode 100644 index 00000000..8ed7d2c0 --- /dev/null +++ b/crates/proto/src/packets/debug_info_packet.rs @@ -0,0 +1,8 @@ +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::actor_unique_id::ActorUniqueID; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct DebugInfoPacket { + pub actor_id: ActorUniqueID, + pub data: String, +} diff --git a/crates/proto/src/packets/inventory_content_packet.rs b/crates/proto/src/packets/inventory_content_packet.rs new file mode 100644 index 00000000..22475c53 --- /dev/null +++ b/crates/proto/src/packets/inventory_content_packet.rs @@ -0,0 +1,11 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +use crate::types::network_item_stack_descriptor::NetworkItemStackDescriptor; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct InventoryContentPacket { + pub inventory_id: VAR, + #[len_repr(VAR::)] + pub slots: Vec, +} diff --git a/crates/proto/src/packets/mob_equipment_packet.rs b/crates/proto/src/packets/mob_equipment_packet.rs new file mode 100644 index 00000000..fd5c6b38 --- /dev/null +++ b/crates/proto/src/packets/mob_equipment_packet.rs @@ -0,0 +1,13 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +use crate::types::network_item_stack_descriptor::NetworkItemStackDescriptor; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct MobEquipmentPacket { + pub runtime_id: VAR, + pub item_stack_descriptor: NetworkItemStackDescriptor, + pub slot: u8, + pub selected_slot: u8, + pub container: u8, +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index bcc437cf..2aebe59e 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -1,17 +1,22 @@ pub mod add_actor_packet; +pub mod add_painting_packet; pub mod animate; pub mod camera_packet; pub mod chunk_radius_updated; pub mod client_cache_status; pub mod command_request_packet; pub mod container_close_packet; +pub mod container_open_packet; pub mod correct_player_move_prediction_packet; +pub mod debug_info_packet; pub mod disconnect; pub mod emote_list; pub mod handshake_server_to_client; pub mod interact; +pub mod inventory_content_packet; pub mod level_chunk; pub mod login; +pub mod mob_equipment_packet; pub mod modal_form_request; pub mod modal_form_response; pub mod network_settings; @@ -20,6 +25,7 @@ pub mod packet_violation_warning; pub mod play_status; pub mod player_action; pub mod player_auth_input; +pub mod player_hotbar_packet; pub mod player_move; pub mod remove_actor_packet; pub mod request_chunk_radius; @@ -30,6 +36,7 @@ pub mod server_player_post_move_position_packet; pub mod server_settings_request; pub mod server_settings_response; pub mod set_local_player_as_initialized; +pub mod set_time_packet; pub mod set_title_packet; pub mod start_game; pub mod text_message; diff --git a/crates/proto/src/packets/player_hotbar_packet.rs b/crates/proto/src/packets/player_hotbar_packet.rs new file mode 100644 index 00000000..d6aaac9e --- /dev/null +++ b/crates/proto/src/packets/player_hotbar_packet.rs @@ -0,0 +1,26 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_core::ProtoCodec; + +use crate::types::container_id::ContainerID; + +#[derive(Debug, Clone)] +pub struct PlayerHotbarPacket { + pub selected_slot: VAR, + pub container_id: ContainerID, + pub should_select_slot: bool, +} + +impl ProtoCodec for PlayerHotbarPacket { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + unimplemented!() + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + unimplemented!() + } +} diff --git a/crates/proto/src/packets/set_time_packet.rs b/crates/proto/src/packets/set_time_packet.rs new file mode 100644 index 00000000..622343c9 --- /dev/null +++ b/crates/proto/src/packets/set_time_packet.rs @@ -0,0 +1,7 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct SetTimePacket { + pub time: VAR, +} diff --git a/crates/proto/src/types/container_id.rs b/crates/proto/src/types/container_id.rs new file mode 100644 index 00000000..0636f50c --- /dev/null +++ b/crates/proto/src/types/container_id.rs @@ -0,0 +1,33 @@ +use bedrockrs_core::int::{BE, VAR}; +use bedrockrs_proto_derive::ProtoCodec; + +/// 定义了容器ID的枚举,用于标识不同的容器类型。 +/// Defines an enum for container IDs, used to identify different types of containers. +#[derive(ProtoCodec, Debug, Copy, Clone, Eq, PartialEq)] +#[enum_repr(BE::)] +pub enum ContainerID { + /// 无容器ID,用于表示没有选择任何容器。 + /// No container ID, used to indicate that no container is selected. + CONTAINER_ID_NONE = -1, + /// 库存容器ID,标识玩家的物品栏。 + /// Inventory container ID, identifies the player's inventory. + CONTAINER_ID_INVENTORY = 0, + /// 第一个容器ID,用于标识开始的容器。 + /// First container ID, used to indicate the starting container. + CONTAINER_ID_FIRST = 1, + /// 最后一个容器ID,用于标识结束的容器。 + /// Last container ID, used to indicate the ending container. + CONTAINER_ID_LAST = 100, + /// 非主手容器ID,用于标识玩家的副手物品栏。 + /// Off-hand container ID, identifies the player's off-hand inventory slot. + CONTAINER_ID_OFFHAND = 119, + /// 防御容器ID,用于标识玩家的防具栏。 + /// Armor container ID, identifies the player's armor slots. + CONTAINER_ID_ARMOR = 120, + /// 选择槽容器ID,用于标识玩家的选择槽。 + /// Selection slots container ID, identifies the player's selection slots. + CONTAINER_ID_SELECTION_SLOTS = 122, + /// 玩家专属UI容器ID,用于标识玩家的专属UI界面。 + /// Player-only UI container ID, identifies the player's dedicated UI interface. + CONTAINER_ID_PLAYER_ONLY_UI = 124, +} diff --git a/crates/proto/src/types/item_stack_net_id_variant.rs b/crates/proto/src/types/item_stack_net_id_variant.rs new file mode 100644 index 00000000..8df5aa8b --- /dev/null +++ b/crates/proto/src/types/item_stack_net_id_variant.rs @@ -0,0 +1,6 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; +#[derive(ProtoCodec, Debug, Clone)] +pub struct ItemStackNetIdVariant { + pub raw_id: VAR, +} diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index 7d605ed8..dc06334a 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -9,6 +9,7 @@ pub mod chat_restriction_level; pub mod chunk_pos; pub mod command_origin_data; pub mod connection_request; +pub mod container_id; pub mod container_type; pub mod dataitem; pub mod disconnect_reason; @@ -20,9 +21,11 @@ pub mod input_mode; pub mod interact_action; pub mod interaction_model; pub mod inventory_transaction; +pub mod item_stack_net_id_variant; pub mod level_settings; pub mod modal_form_cancel_reason; pub mod network_block_pos; +pub mod network_item_stack_descriptor; pub mod network_permissions; pub mod pack_info_behavior; pub mod pack_info_resource; @@ -39,3 +42,4 @@ pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; pub mod title_type; +pub mod valid; diff --git a/crates/proto/src/types/network_item_stack_descriptor.rs b/crates/proto/src/types/network_item_stack_descriptor.rs new file mode 100644 index 00000000..c28c8713 --- /dev/null +++ b/crates/proto/src/types/network_item_stack_descriptor.rs @@ -0,0 +1,47 @@ +use bedrockrs_core::int::{LE, VAR}; +use bedrockrs_proto_core::ProtoCodec; + +use super::{item_stack_net_id_variant::ItemStackNetIdVariant, valid::Valid}; + +#[derive(Debug, Clone)] +pub enum NetworkItemStackDescriptor { + Invalid { id: VAR }, + Valid { valid: Valid }, +} +impl ProtoCodec for NetworkItemStackDescriptor { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + unimplemented!() + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + let id = VAR::::proto_deserialize(stream)?; + if id.into_inner() == 0 { + Ok(Self::Invalid { id }) + } else { + let stack_size = LE::::proto_deserialize(stream)?; + let aux_value = LE::::proto_deserialize(stream)?; + let include_net_id = bool::proto_deserialize(stream)?; + let include_net_id_data = if include_net_id { + Some(ItemStackNetIdVariant::proto_deserialize(stream)?) + } else { + None + }; + Ok(Self::Valid { + valid: Valid { + id, + stack_size, + aux_value, + include_net_id, + include_net_id_data, + block_runtime_id: VAR::::proto_deserialize(stream)?, + user_data_buffer: String::proto_deserialize(stream)?, + }, + }) + } + } +} diff --git a/crates/proto/src/types/valid.rs b/crates/proto/src/types/valid.rs new file mode 100644 index 00000000..56e54153 --- /dev/null +++ b/crates/proto/src/types/valid.rs @@ -0,0 +1,15 @@ +use bedrockrs_core::int::{LE, VAR}; +use bedrockrs_proto_derive::ProtoCodec; + +use super::item_stack_net_id_variant::ItemStackNetIdVariant; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct Valid { + pub id: VAR, + pub stack_size: LE, + pub aux_value: LE, + pub include_net_id: bool, + pub include_net_id_data: Option, + pub block_runtime_id: VAR, + pub user_data_buffer: String, +}