From 61621d612425411e6d8dff997af52c4e73e75794 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sun, 4 Aug 2024 05:40:56 +0800 Subject: [PATCH 01/22] add player_action/add actor_link datatype . --- crates/proto/src/gamepacket.rs | 9 ++--- crates/proto/src/login/provider/default.rs | 2 +- crates/proto/src/packets/animate.rs | 2 -- crates/proto/src/packets/mod.rs | 2 ++ crates/proto/src/packets/player_action.rs | 33 +++++++++++++++++++ .../proto/src/packets/property_sync_data.rs | 3 ++ crates/proto/src/types/actor_link.rs | 9 +++++ crates/proto/src/types/chunk_pos.rs | 4 +-- crates/proto/src/types/mod.rs | 1 + 9 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 crates/proto/src/packets/player_action.rs create mode 100644 crates/proto/src/packets/property_sync_data.rs create mode 100644 crates/proto/src/types/actor_link.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index b9167864..85e1ed55 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -18,6 +18,7 @@ use crate::packets::network_settings::NetworkSettingsPacket; use crate::packets::network_settings_request::NetworkSettingsRequestPacket; 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_move::MovePlayerPacket; use crate::packets::request_chunk_radius::RequestChunkRadiusPacket; @@ -70,7 +71,7 @@ pub enum GamePacket { Interact(InteractPacket), BlockPickRequest(), EntityPickRequest(), - PlayerAction(), + PlayerAction(PlayerActionPacket), HurtArmor(), SetEntityData(), SetEntityMotion(), @@ -495,8 +496,8 @@ impl GamePacket { GamePacket::EntityPickRequest() => { unimplemented!() } - GamePacket::PlayerAction() => { - unimplemented!() + GamePacket::PlayerAction(pk) => { + ser_packet!(stream, GamePacket::PlayerActionID, pk) } GamePacket::HurtArmor() => { unimplemented!() @@ -965,7 +966,7 @@ impl GamePacket { unimplemented!() } GamePacket::PlayerActionID => { - unimplemented!() + GamePacket::PlayerAction(de_packet!(stream, PlayerActionPacket)) } GamePacket::HurtArmorID => { unimplemented!() diff --git a/crates/proto/src/login/provider/default.rs b/crates/proto/src/login/provider/default.rs index fb0d1d39..20d2eb52 100644 --- a/crates/proto/src/login/provider/default.rs +++ b/crates/proto/src/login/provider/default.rs @@ -28,7 +28,7 @@ impl DefaultLoginProvider { impl LoginProviderServer for DefaultLoginProvider { fn compression(&self) -> Compression { - Compression::Snappy { threshold: 1 } + Compression::None } fn encryption_enabled(&self) -> bool { false diff --git a/crates/proto/src/packets/animate.rs b/crates/proto/src/packets/animate.rs index e4c4cfa9..8cc6fa04 100644 --- a/crates/proto/src/packets/animate.rs +++ b/crates/proto/src/packets/animate.rs @@ -58,8 +58,6 @@ impl ProtoCodec for AnimatePacket { } }; - println!("{:?}", &stream.get_ref()[(stream.position() as usize)..]); - Ok(Self { action, target_runtime_id, diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index 373ac4e5..3eaf04e1 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -24,3 +24,5 @@ pub mod server_settings_response; pub mod set_local_player_as_initialized; pub mod start_game; pub mod text_message; +pub mod player_action; +pub mod property_sync_data; \ No newline at end of file diff --git a/crates/proto/src/packets/player_action.rs b/crates/proto/src/packets/player_action.rs new file mode 100644 index 00000000..c8f8403f --- /dev/null +++ b/crates/proto/src/packets/player_action.rs @@ -0,0 +1,33 @@ +use crate::types::network_block_pos::NetworkBlockPos; +use bedrockrs_core::int::VAR; +use bedrockrs_shared::actor_runtime_id::ActorRuntimeID; + +#[derive(Debug, Clone)] +pub struct PlayerActionPacket { + pub player_runtime_id: ActorRuntimeID, + pub action: VAR, + pub block_pos: NetworkBlockPos, + pub result_pos: NetworkBlockPos, + pub face: VAR, +} +use bedrockrs_proto_core::ProtoCodec; +impl ProtoCodec for PlayerActionPacket { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + Ok(()) + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + Ok(Self { + player_runtime_id: ActorRuntimeID::proto_deserialize(stream)?, + action: VAR::::proto_deserialize(stream)?, + block_pos: NetworkBlockPos::proto_deserialize(stream)?, + result_pos: NetworkBlockPos::proto_deserialize(stream)?, + face: VAR::::proto_deserialize(stream)?, + }) + } +} diff --git a/crates/proto/src/packets/property_sync_data.rs b/crates/proto/src/packets/property_sync_data.rs new file mode 100644 index 00000000..b28b04f6 --- /dev/null +++ b/crates/proto/src/packets/property_sync_data.rs @@ -0,0 +1,3 @@ + + + diff --git a/crates/proto/src/types/actor_link.rs b/crates/proto/src/types/actor_link.rs new file mode 100644 index 00000000..43a57e1e --- /dev/null +++ b/crates/proto/src/types/actor_link.rs @@ -0,0 +1,9 @@ +use bedrockrs_shared::actor_unique_id::ActorUniqueID; + +pub struct ActorLink { + actor_unique_id_a: ActorUniqueID, + actor_unique_id_b: ActorUniqueID, + link_type: u8, + immediate: bool, + passenger_seat_id: bool, +} diff --git a/crates/proto/src/types/chunk_pos.rs b/crates/proto/src/types/chunk_pos.rs index f015f7bd..ea956256 100644 --- a/crates/proto/src/types/chunk_pos.rs +++ b/crates/proto/src/types/chunk_pos.rs @@ -10,8 +10,8 @@ pub struct ChunkPos { impl ChunkPos { pub fn new(x: i32, z: i32) -> Self { ChunkPos { - x: VAR::new(x), - z: VAR::new(z), + x: VAR::::new(x), + z: VAR::::new(z) } } } diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index 912156b6..a9a01eef 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -29,3 +29,4 @@ pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; +pub mod actor_link; \ No newline at end of file From 30122a0c70e9e099117116572271cb4bd10a0ec4 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sun, 4 Aug 2024 06:25:26 +0800 Subject: [PATCH 02/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20player=5Faction.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/proto/src/packets/player_action.rs | 24 ++--------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/crates/proto/src/packets/player_action.rs b/crates/proto/src/packets/player_action.rs index c8f8403f..f56b77b6 100644 --- a/crates/proto/src/packets/player_action.rs +++ b/crates/proto/src/packets/player_action.rs @@ -1,8 +1,8 @@ use crate::types::network_block_pos::NetworkBlockPos; use bedrockrs_core::int::VAR; use bedrockrs_shared::actor_runtime_id::ActorRuntimeID; - -#[derive(Debug, Clone)] +use bedrockrs_proto_core::ProtoCodec; +#[derive(ProtoCodec,Debug, Clone)] pub struct PlayerActionPacket { pub player_runtime_id: ActorRuntimeID, pub action: VAR, @@ -10,24 +10,4 @@ pub struct PlayerActionPacket { pub result_pos: NetworkBlockPos, pub face: VAR, } -use bedrockrs_proto_core::ProtoCodec; -impl ProtoCodec for PlayerActionPacket { - fn proto_serialize( - &self, - stream: &mut Vec, - ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { - Ok(()) - } - fn proto_deserialize( - stream: &mut std::io::Cursor<&[u8]>, - ) -> Result { - Ok(Self { - player_runtime_id: ActorRuntimeID::proto_deserialize(stream)?, - action: VAR::::proto_deserialize(stream)?, - block_pos: NetworkBlockPos::proto_deserialize(stream)?, - result_pos: NetworkBlockPos::proto_deserialize(stream)?, - face: VAR::::proto_deserialize(stream)?, - }) - } -} From 0a936abd017a8168b8018b7063ce6e072ca6661c Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sun, 4 Aug 2024 06:47:17 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20player=5Faction.rs?= =?UTF-8?q?=20/add=20PlayerActionType=20enum=20to=20types.rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/proto/src/packets/player_action.rs | 10 ++--- crates/proto/src/types/mod.rs | 3 +- crates/proto/src/types/player_action_type.rs | 47 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 crates/proto/src/types/player_action_type.rs diff --git a/crates/proto/src/packets/player_action.rs b/crates/proto/src/packets/player_action.rs index f56b77b6..26447f3e 100644 --- a/crates/proto/src/packets/player_action.rs +++ b/crates/proto/src/packets/player_action.rs @@ -1,13 +1,13 @@ -use crate::types::network_block_pos::NetworkBlockPos; +use crate::types::{network_block_pos::NetworkBlockPos, player_action_type::PlayerActionType}; use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::actor_runtime_id::ActorRuntimeID; -use bedrockrs_proto_core::ProtoCodec; -#[derive(ProtoCodec,Debug, Clone)] + +#[derive(ProtoCodec, Debug, Clone)] pub struct PlayerActionPacket { pub player_runtime_id: ActorRuntimeID, - pub action: VAR, + pub action: PlayerActionType, pub block_pos: NetworkBlockPos, pub result_pos: NetworkBlockPos, pub face: VAR, } - diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index a9a01eef..e6fce58f 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -29,4 +29,5 @@ pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; -pub mod actor_link; \ No newline at end of file +pub mod actor_link; +pub mod player_action_type; \ No newline at end of file diff --git a/crates/proto/src/types/player_action_type.rs b/crates/proto/src/types/player_action_type.rs new file mode 100644 index 00000000..206df0fc --- /dev/null +++ b/crates/proto/src/types/player_action_type.rs @@ -0,0 +1,47 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + + +#[derive(ProtoCodec, Debug, Copy, Clone, Eq, PartialEq)] +#[enum_repr(VAR::)] +pub enum PlayerActionType { + Unknown = -1, + StartDestroyBlock = 0, + AbortDestroyBlock = 1, + StopDestroyBlock = 2, + GetUpdatedBlock = 3, + DropItem = 4, + StartSleeping = 5, + StopSleeping = 6, + Respawn = 7, + StartJump = 8, + StartSprinting = 9, + StopSprinting = 10, + StartSneaking = 11, + StopSneaking = 12, + CreativeDestroyBlock = 13, + ChangeDimensionAck = 14, + StartGliding = 15, + StopGliding = 16, + DenyDestroyBlock = 17, + CrackBlock = 18, + ChangeSkin = 19, + DeprecatedUpdatedEnchantingSeed = 20, + StartSwimming = 21, + StopSwimming = 22, + StartSpinAttack = 23, + StopSpinAttack = 24, + InteractWithBlock = 25, + PredictDestroyBlock = 26, + ContinueDestroyBlock = 27, + StartItemUseOn = 28, + StopItemUseOn = 29, + HandledTeleport = 30, + MissedSwing = 31, + StartCrawling = 32, + StopCrawling = 33, + StartFlying = 34, + StopFlying = 35, + ClientAckServerData = 36, + Count = 37, +} From e7b47f292da57689be4a44a1b9f3fdf13377e109 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Sun, 4 Aug 2024 06:53:06 +0800 Subject: [PATCH 04/22] cargo fmt --- crates/proto/src/packets/mod.rs | 4 ++-- crates/proto/src/packets/property_sync_data.rs | 2 -- crates/proto/src/types/chunk_pos.rs | 2 +- crates/proto/src/types/mod.rs | 4 ++-- crates/proto/src/types/player_action_type.rs | 1 - 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index 3eaf04e1..eb67aff3 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -13,8 +13,10 @@ pub mod network_settings; pub mod network_settings_request; pub mod packet_violation_warning; pub mod play_status; +pub mod player_action; pub mod player_auth_input; pub mod player_move; +pub mod property_sync_data; pub mod request_chunk_radius; pub mod resource_packs_info; pub mod resource_packs_response; @@ -24,5 +26,3 @@ pub mod server_settings_response; pub mod set_local_player_as_initialized; pub mod start_game; pub mod text_message; -pub mod player_action; -pub mod property_sync_data; \ No newline at end of file diff --git a/crates/proto/src/packets/property_sync_data.rs b/crates/proto/src/packets/property_sync_data.rs index b28b04f6..8b137891 100644 --- a/crates/proto/src/packets/property_sync_data.rs +++ b/crates/proto/src/packets/property_sync_data.rs @@ -1,3 +1 @@ - - diff --git a/crates/proto/src/types/chunk_pos.rs b/crates/proto/src/types/chunk_pos.rs index ea956256..11f2e9c8 100644 --- a/crates/proto/src/types/chunk_pos.rs +++ b/crates/proto/src/types/chunk_pos.rs @@ -11,7 +11,7 @@ impl ChunkPos { pub fn new(x: i32, z: i32) -> Self { ChunkPos { x: VAR::::new(x), - z: VAR::::new(z) + z: VAR::::new(z), } } } diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index e6fce58f..ba3f9283 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -1,3 +1,4 @@ +pub mod actor_link; pub mod animate_action; pub mod base_game_version; pub mod block_action; @@ -22,6 +23,7 @@ pub mod pack_info_resource; pub mod pack_url; pub mod play_mode; pub mod play_status; +pub mod player_action_type; pub mod player_movement_mode; pub mod player_movement_settings; pub mod resource_packs_response_status; @@ -29,5 +31,3 @@ pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; -pub mod actor_link; -pub mod player_action_type; \ No newline at end of file diff --git a/crates/proto/src/types/player_action_type.rs b/crates/proto/src/types/player_action_type.rs index 206df0fc..b686d6fd 100644 --- a/crates/proto/src/types/player_action_type.rs +++ b/crates/proto/src/types/player_action_type.rs @@ -1,7 +1,6 @@ use bedrockrs_core::int::VAR; use bedrockrs_proto_derive::ProtoCodec; - #[derive(ProtoCodec, Debug, Copy, Clone, Eq, PartialEq)] #[enum_repr(VAR::)] pub enum PlayerActionType { From b35013dbf9471ca0f802765324d53a2565b88c6a Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 04:28:54 +0800 Subject: [PATCH 05/22] add AddActorPacket network datapacket --- crates/proto/Cargo.toml | 2 + crates/proto/src/gamepacket.rs | 11 +- crates/proto/src/packets/add_actor_packet.rs | 28 ++ crates/proto/src/packets/mod.rs | 2 +- .../proto/src/packets/property_sync_data.rs | 1 - crates/proto/src/types/actor_link.rs | 15 +- crates/proto/src/types/actor_link_type.rs | 11 + crates/proto/src/types/actor_type.rs | 329 ++++++++++++++++++ crates/proto/src/types/attribute.rs | 16 + crates/proto/src/types/dataitem.rs | 38 ++ crates/proto/src/types/mod.rs | 5 + crates/proto/src/types/property_sync_data.rs | 47 +++ 12 files changed, 496 insertions(+), 9 deletions(-) create mode 100644 crates/proto/src/packets/add_actor_packet.rs delete mode 100644 crates/proto/src/packets/property_sync_data.rs create mode 100644 crates/proto/src/types/actor_link_type.rs create mode 100644 crates/proto/src/types/actor_type.rs create mode 100644 crates/proto/src/types/attribute.rs create mode 100644 crates/proto/src/types/dataitem.rs create mode 100644 crates/proto/src/types/property_sync_data.rs diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index 291b11ad..f6445def 100644 --- a/crates/proto/Cargo.toml +++ b/crates/proto/Cargo.toml @@ -27,3 +27,5 @@ flate2 = "1.0" snap = "1.1" x509-cert = "0.2" + +bitflags = "2.6.0" diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 85e1ed55..334fcc2e 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -3,6 +3,7 @@ use std::io::{Cursor, Write}; use std::sync::Arc; +use crate::packets::add_actor_packet::AddActorPacket; use crate::packets::animate::AnimatePacket; use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket; use crate::packets::client_cache_status::ClientCacheStatusPacket; @@ -49,7 +50,7 @@ pub enum GamePacket { SetTime(), StartGame(StartGamePacket), AddPlayer(), - AddEntity(), + AddEntity(AddActorPacket), RemoveEntity(), AddItemEntity(), TakeItemEntity(), @@ -430,8 +431,8 @@ impl GamePacket { GamePacket::AddPlayer() => { unimplemented!() } - GamePacket::AddEntity() => { - unimplemented!() + GamePacket::AddEntity(pk) => { + ser_packet!(stream, GamePacket::AddEntityID, pk) } GamePacket::RemoveEntity() => { unimplemented!() @@ -901,9 +902,7 @@ impl GamePacket { GamePacket::AddPlayerID => { unimplemented!() } - GamePacket::AddEntityID => { - unimplemented!() - } + GamePacket::AddEntityID => GamePacket::AddEntity(de_packet!(stream, AddActorPacket)), GamePacket::RemoveEntityID => { unimplemented!() } diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs new file mode 100644 index 00000000..c77a9666 --- /dev/null +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -0,0 +1,28 @@ +use bedrockrs_core::{ + int::{LE, VAR}, + Vec2, Vec3, +}; +use bedrockrs_proto_derive::ProtoCodec; +use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; + +use crate::types::{ + actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, + property_sync_data::PropertySyncData, +}; + +#[derive(ProtoCodec,Debug, Clone)] +pub struct AddActorPacket { + pub target_actor_id: ActorUniqueID, + pub target_runtime_id: ActorRuntimeID, + pub actor_type: ActorType, + pub position: Vec3>, + pub velocity: Vec3>, + pub rotation: Vec2>, + pub y_head_rotation: LE, + pub y_body_rotation: LE, + pub attributes: AttributeList, + #[len_repr(VAR::)] + pub actor_data: Vec, + pub synched_properties: PropertySyncData, + pub actor_links: ActorLinkList, +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index eb67aff3..0dbe2b09 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -1,3 +1,4 @@ +pub mod add_actor_packet; pub mod animate; pub mod chunk_radius_updated; pub mod client_cache_status; @@ -16,7 +17,6 @@ pub mod play_status; pub mod player_action; pub mod player_auth_input; pub mod player_move; -pub mod property_sync_data; pub mod request_chunk_radius; pub mod resource_packs_info; pub mod resource_packs_response; diff --git a/crates/proto/src/packets/property_sync_data.rs b/crates/proto/src/packets/property_sync_data.rs deleted file mode 100644 index 8b137891..00000000 --- a/crates/proto/src/packets/property_sync_data.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/proto/src/types/actor_link.rs b/crates/proto/src/types/actor_link.rs index 43a57e1e..5d131e8c 100644 --- a/crates/proto/src/types/actor_link.rs +++ b/crates/proto/src/types/actor_link.rs @@ -1,9 +1,22 @@ + +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::actor_unique_id::ActorUniqueID; +use super::actor_link_type::ActorLinkType; + +#[derive(ProtoCodec,Debug, Clone)] pub struct ActorLink { actor_unique_id_a: ActorUniqueID, actor_unique_id_b: ActorUniqueID, - link_type: u8, + link_type: ActorLinkType, immediate: bool, passenger_seat_id: bool, } + +#[derive(ProtoCodec,Debug, Clone)] +pub struct ActorLinkList +{ + #[len_repr(VAR::)] + pub links: Vec, +} \ No newline at end of file diff --git a/crates/proto/src/types/actor_link_type.rs b/crates/proto/src/types/actor_link_type.rs new file mode 100644 index 00000000..16fb01ca --- /dev/null +++ b/crates/proto/src/types/actor_link_type.rs @@ -0,0 +1,11 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + + +#[derive(ProtoCodec,Debug, Clone)] +#[enum_repr(VAR::)] +pub enum ActorLinkType { + None = 0, + Riding = 1, + Passenger = 2, +} \ No newline at end of file diff --git a/crates/proto/src/types/actor_type.rs b/crates/proto/src/types/actor_type.rs new file mode 100644 index 00000000..45d7a110 --- /dev/null +++ b/crates/proto/src/types/actor_type.rs @@ -0,0 +1,329 @@ +use bedrockrs_proto_core::ProtoCodec; +use bitflags::bitflags; +bitflags! { + struct Flags: isize { + const UNDEFINED = 1; + const TYPE_MASK = 0x000000ff; + const MOB = 0x00000100; + const PATHFINDER_MOB = 0x00000200 | Self::MOB.bits(); + const MONSTER = 0x00000800 | Self::PATHFINDER_MOB.bits(); + const ANIMAL = 0x00001000 | Self::PATHFINDER_MOB.bits(); + const TAMABLE_ANIMAL = 0x00004000 | Self::ANIMAL.bits(); + const AMBIENT = 0x00008000 | Self::MOB.bits(); + const UNDEAD_MOB = 0x00010000 | Self::MONSTER.bits(); + const ZOMBIE_MONSTER = 0x00020000 | Self::UNDEAD_MOB.bits(); + const ARTHROPOD = 0x00040000 | Self::MONSTER.bits(); + const MINECART = 0x00080000; + const SKELETONMONSTER = 0x00100000 | Self::UNDEAD_MOB.bits(); + const EQUINEANIMAL = 0x00200000 | Self::TAMABLE_ANIMAL.bits(); + const PROJECTILE = 0x00400000; + const ABSTRACTARROW = 0x00800000; + const WATERANIMAL = 0x00002000 | Self::PATHFINDER_MOB.bits(); + const VILLAGERBASE = 0x01000000 | Self::PATHFINDER_MOB.bits(); + const CHICKEN = 10 | Self::ANIMAL.bits(); + const COW = 11 | Self::ANIMAL.bits(); + const PIG = 12 | Self::ANIMAL.bits(); + const SHEEP = 13 | Self::ANIMAL.bits(); + const WOLF = 14 | Self::TAMABLE_ANIMAL.bits(); + const VILLAGER = 15 | Self::VILLAGERBASE.bits(); + const MUSHROOMCOW = 16 | Self::ANIMAL.bits(); + const SQUID = 17 | Self::WATERANIMAL.bits(); + const RABBIT = 18 | Self::ANIMAL.bits(); + const BAT = 19 | Self::AMBIENT.bits(); + const IRONGOLEM = 20 | Self::PATHFINDER_MOB.bits(); + const SNOWGOLEM = 21 | Self::PATHFINDER_MOB.bits(); + const OCELOT = 22 | Self::TAMABLE_ANIMAL.bits(); + const HORSE = 23 | Self::EQUINEANIMAL.bits(); + const POLARBEAR = 28 | Self::ANIMAL.bits(); + const LLAMA = 29 | Self::ANIMAL.bits(); + const PARROT = 30 | Self::TAMABLE_ANIMAL.bits(); + const DOLPHIN = 31 | Self::WATERANIMAL.bits(); + const DONKEY = 24 | Self::EQUINEANIMAL.bits(); + const MULE = 25 | Self::EQUINEANIMAL.bits(); + const SKELETONHORSE = 26 | Self::EQUINEANIMAL.bits() | Self::UNDEAD_MOB.bits(); + const ZOMBIEHORSE = 27 | Self::EQUINEANIMAL.bits() | Self::UNDEAD_MOB.bits(); + const ZOMBIE = 32 | Self::ZOMBIE_MONSTER.bits(); + const CREEPER = 33 | Self::MONSTER.bits(); + const SKELETON = 34 | Self::SKELETONMONSTER.bits(); + const SPIDER = 35 | Self::ARTHROPOD.bits(); + const PIGZOMBIE = 36 | Self::UNDEAD_MOB.bits(); + const SLIME = 37 | Self::MONSTER.bits(); + const ENDERMAN = 38 | Self::MONSTER.bits(); + const SILVERFISH = 39 | Self::ARTHROPOD.bits(); + const CAVESPIDER = 40 | Self::ARTHROPOD.bits(); + const GHAST = 41 | Self::MONSTER.bits(); + const LAVASLIME = 42 | Self::MONSTER.bits(); + const BLAZE = 43 | Self::MONSTER.bits(); + const ZOMBIEVILLAGER = 44 | Self::ZOMBIE_MONSTER.bits(); + const WITCH = 45 | Self::MONSTER.bits(); + const STRAY = 46 | Self::SKELETONMONSTER.bits(); + const HUSK = 47 | Self::ZOMBIE_MONSTER.bits(); + const WITHERSKELETON = 48 | Self::SKELETONMONSTER.bits(); + const GUARDIAN = 49 | Self::MONSTER.bits(); + const ELDERGUARDIAN = 50 | Self::MONSTER.bits(); + const NPC = 51 | Self::MOB.bits(); + const WITHERBOSS = 52 | Self::UNDEAD_MOB.bits(); + const DRAGON = 53 | Self::MONSTER.bits(); + const SHULKER = 54 | Self::MONSTER.bits(); + const ENDERMITE = 55 | Self::ARTHROPOD.bits(); + const AGENT = 56 | Self::MOB.bits(); + const VINDICATOR = 57 | Self::MONSTER.bits(); + const PHANTOM = 58 | Self::UNDEAD_MOB.bits(); + const ILLAGERBEAST = 59 | Self::MONSTER.bits(); + const ARMORSTAND = 61 | Self::MOB.bits(); + const TRIPODCAMERA = 62 | Self::MOB.bits(); + const PLAYER = 63 | Self::MOB.bits(); + const ITEMENTITY = 64; + const PRIMEDTNT = 65; + const FALLINGBLOCK = 66; + const MOVINGBLOCK = 67; + const EXPERIENCEPOTION = 68 | Self::PROJECTILE.bits(); + const EXPERIENCE = 69; + const EYEOFENDER = 70; + const ENDERCRYSTAL = 71; + const FIREWORKSROCKET = 72; + const TRIDENT = 73 | Self::PROJECTILE.bits() | Self::ABSTRACTARROW.bits(); + const TURTLE = 74 | Self::ANIMAL.bits(); + const CAT = 75 | Self::TAMABLE_ANIMAL.bits(); + const SHULKERBULLET = 76 | Self::PROJECTILE.bits(); + const FISHINGHOOK = 77; + const CHALKBOARD = 78; + const DRAGONFIREBALL = 79 | Self::PROJECTILE.bits(); + const ARROW = 80 | Self::PROJECTILE.bits() | Self::ABSTRACTARROW.bits(); + const SNOWBALL = 81 | Self::PROJECTILE.bits(); + const THROWNEGG = 82 | Self::PROJECTILE.bits(); + const PAINTING = 83; + const LARGEFIREBALL = 85 | Self::PROJECTILE.bits(); + const THROWNPOTION = 86 | Self::PROJECTILE.bits(); + const ENDERPEARL = 87 | Self::PROJECTILE.bits(); + const LEASHKNOT = 88; + const WITHERSKULL = 89 | Self::PROJECTILE.bits(); + const BOATRIDEABLE = 90; + const WITHERSKULLDANGEROUS = 91 | Self::PROJECTILE.bits(); + const LIGHTNINGBOLT = 93; + const SMALLFIREBALL = 94 | Self::PROJECTILE.bits(); + const AREAEFFECTCLOUD = 95; + const LINGERINGPOTION = 101 | Self::PROJECTILE.bits(); + const LLAMASPIT = 102 | Self::PROJECTILE.bits(); + const EVOCATIONFANG = 103 | Self::PROJECTILE.bits(); + const EVOCATIONILLAGER = 104 | Self::MONSTER.bits(); + const VEX = 105 | Self::MONSTER.bits(); + const MINECARTRIDEABLE = 84 | Self::MINECART.bits(); + const MINECARTHOPPER = 96 | Self::MINECART.bits(); + const MINECARTTNT = 97 | Self::MINECART.bits(); + const MINECARTCHEST = 98 | Self::MINECART.bits(); + const MINECARTFURNACE = 99 | Self::MINECART.bits(); + const MINECARTCOMMANDBLOCK = 100 | Self::MINECART.bits(); + const ICEBOMB = 106 | Self::PROJECTILE.bits(); + const BALLOON = 107; + const PUFFERFISH = 108 | Self::WATERANIMAL.bits(); + const SALMON = 109 | Self::WATERANIMAL.bits(); + const DROWNED = 110 | Self::ZOMBIE_MONSTER.bits(); + const TROPICALFISH = 111 | Self::WATERANIMAL.bits(); + const FISH = 112 | Self::WATERANIMAL.bits(); + const PANDA = 113 | Self::ANIMAL.bits(); + const PILLAGER = 114 | Self::MONSTER.bits(); + const VILLAGERV2 = 115 | Self::VILLAGERBASE.bits(); + const ZOMBIEVILLAGERV2 = 116 | Self::ZOMBIE_MONSTER.bits(); + const SHIELD = 117; + const WANDERINGTRADER = 118 | Self::PATHFINDER_MOB.bits(); + const LECTERN = 119; + const ELDERGUARDIANGHOST = 120 | Self::MONSTER.bits(); + const FOX = 121 | Self::ANIMAL.bits(); + const BEE = 122 | Self::MOB.bits(); + const PIGLIN = 123 | Self::MOB.bits(); + const HOGLIN = 124 | Self::ANIMAL.bits(); + const STRIDER = 125 | Self::ANIMAL.bits(); + const ZOGLIN = 126 | Self::UNDEAD_MOB.bits(); + const PIGLINBRUTE = 127 | Self::MOB.bits(); + const GOAT = 128 | Self::ANIMAL.bits(); + const GLOWSQUID = 129 | Self::WATERANIMAL.bits(); + const AXOLOTL = 130 | Self::ANIMAL.bits(); + const WARDEN = 131 | Self::MONSTER.bits(); + const FROG = 132 | Self::ANIMAL.bits(); + const TADPOLE = 133 | Self::WATERANIMAL.bits(); + const ALLAY = 134 | Self::MOB.bits(); + const CHESTBOATRIDEABLE = 136 |Self:: BOATRIDEABLE.bits(); + const TRADERLLAMA = 137 | Self::LLAMA.bits(); + const CAMEL = 138 | Self::ANIMAL.bits(); + const SNIFFER = 139 | Self::ANIMAL.bits(); + const BREEZE = 140 | Self::MONSTER.bits(); + const BREEZEWINDCHARGEPROJECTILE = 141 | Self::PROJECTILE.bits(); + const ARMADILLO = 142 | Self::ANIMAL.bits(); + const WINDCHARGEPROJECTILE = 143 |Self:: PROJECTILE.bits(); + const BOGGED = 144 | Self::SKELETONMONSTER.bits(); + const OMINOUSITEMSPAWNER = 145; + } +} + +#[derive(Debug, Clone)] +pub enum ActorType { + Undefined = Flags::UNDEFINED.bits(), + TypeMask = Flags::TYPE_MASK.bits(), + Mob = Flags::MOB.bits(), + PathfinderMob = Flags::PATHFINDER_MOB.bits(), + Monster = Flags::MONSTER.bits(), + Animal = Flags::ANIMAL.bits(), + TamableAnimal = Flags::TAMABLE_ANIMAL.bits(), + Ambient = Flags::AMBIENT.bits(), + UndeadMob = Flags::UNDEAD_MOB.bits(), + ZombieMonster = Flags::ZOMBIE_MONSTER.bits(), + Arthropod = Flags::ARTHROPOD.bits(), + Minecart = Flags::MINECART.bits(), + SkeletonMonster = Flags::SKELETONMONSTER.bits(), + EquineAnimal = Flags::EQUINEANIMAL.bits(), + Projectile = Flags::PROJECTILE.bits(), + AbstractArrow = Flags::ABSTRACTARROW.bits(), + WaterAnimal = Flags::WATERANIMAL.bits(), + VillagerBase = Flags::VILLAGERBASE.bits(), + Chicken = Flags::CHICKEN.bits(), + Cow = Flags::COW.bits(), + Pig = Flags::PIG.bits(), + Sheep = Flags::SHEEP.bits(), + Wolf = Flags::WOLF.bits(), + Villager = Flags::VILLAGER.bits(), + MushroomCow = Flags::MUSHROOMCOW.bits(), + Squid = Flags::SQUID.bits(), + Rabbit = Flags::RABBIT.bits(), + Bat = Flags::BAT.bits(), + IronGolem = Flags::IRONGOLEM.bits(), + SnowGolem = Flags::SNOWGOLEM.bits(), + Ocelot = Flags::OCELOT.bits(), + Horse = Flags::HORSE.bits(), + PolarBear = Flags::POLARBEAR.bits(), + Llama = Flags::LLAMA.bits(), + Parrot = Flags::PARROT.bits(), + Dolphin = Flags::DOLPHIN.bits(), + Donkey = Flags::DONKEY.bits(), + Mule = Flags::MULE.bits(), + SkeletonHorse = Flags::SKELETONHORSE.bits(), + ZombieHorse = Flags::ZOMBIEHORSE.bits(), + Zombie = Flags::ZOMBIE.bits(), + Creeper = Flags::CREEPER.bits(), + Skeleton = Flags::SKELETON.bits(), + Spider = Flags::SPIDER.bits(), + PigZombie = Flags::PIGZOMBIE.bits(), + Slime = Flags::SLIME.bits(), + EnderMan = Flags::ENDERMAN.bits(), + Silverfish = Flags::SILVERFISH.bits(), + CaveSpider = Flags::CAVESPIDER.bits(), + Ghast = Flags::GHAST.bits(), + LavaSlime = Flags::LAVASLIME.bits(), + Blaze = Flags::BLAZE.bits(), + ZombieVillager = Flags::ZOMBIEVILLAGER.bits(), + Witch = Flags::WITCH.bits(), + Stray = Flags::STRAY.bits(), + Husk = Flags::HUSK.bits(), + WitherSkeleton = Flags::WITHERSKELETON.bits(), + Guardian = Flags::GUARDIAN.bits(), + ElderGuardian = Flags::ELDERGUARDIAN.bits(), + Npc = Flags::NPC.bits(), + WitherBoss = Flags::WITHERBOSS.bits(), + Dragon = Flags::DRAGON.bits(), + Shulker = Flags::SHULKER.bits(), + Endermite = Flags::ENDERMITE.bits(), + Agent = Flags::AGENT.bits(), + Vindicator = Flags::VINDICATOR.bits(), + Phantom = Flags::PHANTOM.bits(), + IllagerBeast = Flags::ILLAGERBEAST.bits(), + ArmorStand = Flags::ARMORSTAND.bits(), + TripodCamera = Flags::TRIPODCAMERA.bits(), + Player = Flags::PLAYER.bits(), + ItemEntity = Flags::ITEMENTITY.bits(), + PrimedTnt = Flags::PRIMEDTNT.bits(), + FallingBlock = Flags::FALLINGBLOCK.bits(), + MovingBlock = Flags::MOVINGBLOCK.bits(), + ExperiencePotion = Flags::EXPERIENCEPOTION.bits(), + Experience = Flags::EXPERIENCE.bits(), + EyeOfEnder = Flags::EYEOFENDER.bits(), + EnderCrystal = Flags::ENDERCRYSTAL.bits(), + FireworksRocket = Flags::FIREWORKSROCKET.bits(), + Trident = Flags::TRIDENT.bits(), + Turtle = Flags::TURTLE.bits(), + Cat = Flags::CAT.bits(), + ShulkerBullet = Flags::SHULKERBULLET.bits(), + FishingHook = Flags::FISHINGHOOK.bits(), + Chalkboard = Flags::CHALKBOARD.bits(), + DragonFireball = Flags::DRAGONFIREBALL.bits(), + Arrow = Flags::ARROW.bits(), + Snowball = Flags::SNOWBALL.bits(), + ThrownEgg = Flags::THROWNEGG.bits(), + Painting = Flags::PAINTING.bits(), + LargeFireball = Flags::LARGEFIREBALL.bits(), + ThrownPotion = Flags::THROWNPOTION.bits(), + Enderpearl = Flags::ENDERPEARL.bits(), + LeashKnot = Flags::LEASHKNOT.bits(), + WitherSkull = Flags::WITHERSKULL.bits(), + BoatRideable = Flags::BOATRIDEABLE.bits(), + WitherSkullDangerous = Flags::WITHERSKULLDANGEROUS.bits(), + LightningBolt = Flags::LIGHTNINGBOLT.bits(), + SmallFireball = Flags::SMALLFIREBALL.bits(), + AreaEffectCloud = Flags::AREAEFFECTCLOUD.bits(), + LingeringPotion = Flags::LINGERINGPOTION.bits(), + LlamaSpit = Flags::LLAMASPIT.bits(), + EvocationFang = Flags::EVOCATIONFANG.bits(), + EvocationIllager = Flags::EVOCATIONILLAGER.bits(), + Vex = Flags::VEX.bits(), + MinecartRideable = Flags::MINECARTRIDEABLE.bits(), + MinecartHopper = Flags::MINECARTHOPPER.bits(), + MinecartTNT = Flags::MINECARTTNT.bits(), + MinecartChest = Flags::MINECARTCHEST.bits(), + MinecartFurnace = Flags::MINECARTFURNACE.bits(), + MinecartCommandBlock = Flags::MINECARTCOMMANDBLOCK.bits(), + IceBomb = Flags::ICEBOMB.bits(), + Balloon = Flags::BALLOON.bits(), + Pufferfish = Flags::PUFFERFISH.bits(), + Salmon = Flags::SALMON.bits(), + Drowned = Flags::DROWNED.bits(), + Tropicalfish = Flags::TROPICALFISH.bits(), + Fish = Flags::FISH.bits(), + Panda = Flags::PANDA.bits(), + Pillager = Flags::PILLAGER.bits(), + VillagerV2 = Flags::VILLAGERV2.bits(), + ZombieVillagerV2 = Flags::ZOMBIEVILLAGERV2.bits(), + Shield = Flags::SHIELD.bits(), + WanderingTrader = Flags::WANDERINGTRADER.bits(), + Lectern = Flags::LECTERN.bits(), + ElderGuardianGhost = Flags::ELDERGUARDIANGHOST.bits(), + Fox = Flags::FOX.bits(), + Bee = Flags::BEE.bits(), + Piglin = Flags::PIGLIN.bits(), + Hoglin = Flags::HOGLIN.bits(), + Strider = Flags::STRIDER.bits(), + Zoglin = Flags::ZOGLIN.bits(), + PiglinBrute = Flags::PIGLINBRUTE.bits(), + Goat = Flags::GOAT.bits(), + GlowSquid = Flags::GLOWSQUID.bits(), + Axolotl = Flags::AXOLOTL.bits(), + Warden = Flags::WARDEN.bits(), + Frog = Flags::FROG.bits(), + Tadpole = Flags::TADPOLE.bits(), + Allay = Flags::ALLAY.bits(), + ChestBoatRideable = Flags::CHESTBOATRIDEABLE.bits(), + TraderLlama = Flags::TRADERLLAMA.bits(), + Camel = Flags::CAMEL.bits(), + Sniffer = Flags::SNIFFER.bits(), + Breeze = Flags::BREEZE.bits(), + BreezeWindChargeProjectile = Flags::BREEZEWINDCHARGEPROJECTILE.bits(), + Armadillo = Flags::ARMADILLO.bits(), + WindChargeProjectile = Flags::WINDCHARGEPROJECTILE.bits(), + Bogged = Flags::BOGGED.bits(), + OminousItemSpawner = Flags::OMINOUSITEMSPAWNER.bits(), +} + +impl ProtoCodec for ActorType { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + + Ok(()) + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + + Ok(Self::Pig) + } +} diff --git a/crates/proto/src/types/attribute.rs b/crates/proto/src/types/attribute.rs new file mode 100644 index 00000000..26def0f1 --- /dev/null +++ b/crates/proto/src/types/attribute.rs @@ -0,0 +1,16 @@ +use bedrockrs_core::int::{LE, VAR}; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec,Debug, Clone)] +pub struct Attribute { + name: String, + min: LE, + current: LE, + max: LE, +} + +#[derive(ProtoCodec,Debug, Clone)] +pub struct AttributeList { + #[len_repr(VAR::)] + attributes: Vec, +} diff --git a/crates/proto/src/types/dataitem.rs b/crates/proto/src/types/dataitem.rs new file mode 100644 index 00000000..3e8c908a --- /dev/null +++ b/crates/proto/src/types/dataitem.rs @@ -0,0 +1,38 @@ +use bedrockrs_core::{ + int::{LE, VAR}, + Vec3, +}; +use bedrockrs_nbt::NbtTag; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec)] +struct DataItem { + id: VAR, + value: DataItemValue, +} +enum DataItemValue { + ValByte(u8), + ValShort(i16), + ValInt(i32), + ValFloat(f32), + ValString(String), + ValCompoundTag(NbtTag), + ValPos(Vec3>), + ValInt64(LE), + ValVec3(Vec3>), +} +use bedrockrs_proto_core::ProtoCodec; +impl ProtoCodec for DataItemValue { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + Ok(()) + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + Ok(Self::ValByte(0)) + } +} diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index ba3f9283..92abe369 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -1,10 +1,13 @@ pub mod actor_link; +pub mod actor_type; pub mod animate_action; +pub mod attribute; pub mod base_game_version; pub mod block_action; pub mod chat_restriction_level; pub mod chunk_pos; pub mod connection_request; +pub mod dataitem; pub mod disconnect_reason; pub mod edu_shared_uri_resource; pub mod experiments; @@ -31,3 +34,5 @@ pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; +pub mod property_sync_data; +pub mod actor_link_type; \ No newline at end of file diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs new file mode 100644 index 00000000..b9fb482f --- /dev/null +++ b/crates/proto/src/types/property_sync_data.rs @@ -0,0 +1,47 @@ +use bedrockrs_core::int::{LE, VAR}; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec,Debug, Clone)] +struct IntEntry { + index: VAR, + data: VAR, +} +#[derive(ProtoCodec,Debug, Clone)] +struct IntEntriesList { + #[len_repr(VAR::)] + entries: Vec, +} + +#[derive(ProtoCodec,Debug, Clone)] +struct FloatEntry { + index: VAR, + data: LE, +} + +#[derive(ProtoCodec,Debug, Clone)] +struct FloatEntriesList { + #[len_repr(VAR::)] + entries: Vec, +} + +#[derive(Debug, Clone)] +pub enum PropertySyncData { + Int(IntEntriesList), + Float(FloatEntriesList), +} + +use bedrockrs_proto_core::ProtoCodec; +impl ProtoCodec for PropertySyncData { + fn proto_serialize( + &self, + stream: &mut Vec, + ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { + Ok(()) + } + + fn proto_deserialize( + stream: &mut std::io::Cursor<&[u8]>, + ) -> Result { + Ok(Self::Int(IntEntriesList::proto_deserialize(stream)?)) + } +} From 58fd45ff8f9a0bdd41db5ce23cdc44f005251cb0 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 04:32:13 +0800 Subject: [PATCH 06/22] add AddActorPacket network datapacket +fmt --- crates/proto/src/packets/add_actor_packet.rs | 2 +- crates/proto/src/types/actor_link.rs | 10 ++++------ crates/proto/src/types/actor_link_type.rs | 5 ++--- crates/proto/src/types/actor_type.rs | 2 -- crates/proto/src/types/attribute.rs | 4 ++-- crates/proto/src/types/mod.rs | 4 ++-- crates/proto/src/types/property_sync_data.rs | 8 ++++---- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs index c77a9666..8ecf48d6 100644 --- a/crates/proto/src/packets/add_actor_packet.rs +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -10,7 +10,7 @@ use crate::types::{ property_sync_data::PropertySyncData, }; -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] pub struct AddActorPacket { pub target_actor_id: ActorUniqueID, pub target_runtime_id: ActorRuntimeID, diff --git a/crates/proto/src/types/actor_link.rs b/crates/proto/src/types/actor_link.rs index 5d131e8c..b6bb5ec0 100644 --- a/crates/proto/src/types/actor_link.rs +++ b/crates/proto/src/types/actor_link.rs @@ -1,11 +1,10 @@ - use bedrockrs_core::int::VAR; use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::actor_unique_id::ActorUniqueID; use super::actor_link_type::ActorLinkType; -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] pub struct ActorLink { actor_unique_id_a: ActorUniqueID, actor_unique_id_b: ActorUniqueID, @@ -14,9 +13,8 @@ pub struct ActorLink { passenger_seat_id: bool, } -#[derive(ProtoCodec,Debug, Clone)] -pub struct ActorLinkList -{ +#[derive(ProtoCodec, Debug, Clone)] +pub struct ActorLinkList { #[len_repr(VAR::)] pub links: Vec, -} \ No newline at end of file +} diff --git a/crates/proto/src/types/actor_link_type.rs b/crates/proto/src/types/actor_link_type.rs index 16fb01ca..759895f3 100644 --- a/crates/proto/src/types/actor_link_type.rs +++ b/crates/proto/src/types/actor_link_type.rs @@ -1,11 +1,10 @@ use bedrockrs_core::int::VAR; use bedrockrs_proto_derive::ProtoCodec; - -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] #[enum_repr(VAR::)] pub enum ActorLinkType { None = 0, Riding = 1, Passenger = 2, -} \ No newline at end of file +} diff --git a/crates/proto/src/types/actor_type.rs b/crates/proto/src/types/actor_type.rs index 45d7a110..286f16ab 100644 --- a/crates/proto/src/types/actor_type.rs +++ b/crates/proto/src/types/actor_type.rs @@ -316,14 +316,12 @@ impl ProtoCodec for ActorType { &self, stream: &mut Vec, ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { - Ok(()) } fn proto_deserialize( stream: &mut std::io::Cursor<&[u8]>, ) -> Result { - Ok(Self::Pig) } } diff --git a/crates/proto/src/types/attribute.rs b/crates/proto/src/types/attribute.rs index 26def0f1..e1236fcc 100644 --- a/crates/proto/src/types/attribute.rs +++ b/crates/proto/src/types/attribute.rs @@ -1,7 +1,7 @@ use bedrockrs_core::int::{LE, VAR}; use bedrockrs_proto_derive::ProtoCodec; -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] pub struct Attribute { name: String, min: LE, @@ -9,7 +9,7 @@ pub struct Attribute { max: LE, } -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] pub struct AttributeList { #[len_repr(VAR::)] attributes: Vec, diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index 92abe369..ed8a5665 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -1,4 +1,5 @@ pub mod actor_link; +pub mod actor_link_type; pub mod actor_type; pub mod animate_action; pub mod attribute; @@ -29,10 +30,9 @@ pub mod play_status; pub mod player_action_type; pub mod player_movement_mode; pub mod player_movement_settings; +pub mod property_sync_data; pub mod resource_packs_response_status; pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; -pub mod property_sync_data; -pub mod actor_link_type; \ No newline at end of file diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs index b9fb482f..82de375f 100644 --- a/crates/proto/src/types/property_sync_data.rs +++ b/crates/proto/src/types/property_sync_data.rs @@ -1,24 +1,24 @@ use bedrockrs_core::int::{LE, VAR}; use bedrockrs_proto_derive::ProtoCodec; -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] struct IntEntry { index: VAR, data: VAR, } -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] struct IntEntriesList { #[len_repr(VAR::)] entries: Vec, } -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] struct FloatEntry { index: VAR, data: LE, } -#[derive(ProtoCodec,Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] struct FloatEntriesList { #[len_repr(VAR::)] entries: Vec, From a59d541ec850d1a55809cb637d02040eeb9267bc Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 04:40:09 +0800 Subject: [PATCH 07/22] add DataItemList --- crates/proto/src/packets/add_actor_packet.rs | 6 ++---- crates/proto/src/types/dataitem.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs index 8ecf48d6..c0767ba4 100644 --- a/crates/proto/src/packets/add_actor_packet.rs +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -6,8 +6,7 @@ use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; use crate::types::{ - actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, - property_sync_data::PropertySyncData, + actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, dataitem::DataItemList, property_sync_data::PropertySyncData }; #[derive(ProtoCodec, Debug, Clone)] @@ -21,8 +20,7 @@ pub struct AddActorPacket { pub y_head_rotation: LE, pub y_body_rotation: LE, pub attributes: AttributeList, - #[len_repr(VAR::)] - pub actor_data: Vec, + pub actor_data: DataItemList, pub synched_properties: PropertySyncData, pub actor_links: ActorLinkList, } diff --git a/crates/proto/src/types/dataitem.rs b/crates/proto/src/types/dataitem.rs index 3e8c908a..90ccf6ae 100644 --- a/crates/proto/src/types/dataitem.rs +++ b/crates/proto/src/types/dataitem.rs @@ -5,11 +5,12 @@ use bedrockrs_core::{ use bedrockrs_nbt::NbtTag; use bedrockrs_proto_derive::ProtoCodec; -#[derive(ProtoCodec)] +#[derive(ProtoCodec, Debug, Clone)] struct DataItem { id: VAR, value: DataItemValue, } +#[derive(Debug, Clone)] enum DataItemValue { ValByte(u8), ValShort(i16), @@ -36,3 +37,9 @@ impl ProtoCodec for DataItemValue { Ok(Self::ValByte(0)) } } + +#[derive(ProtoCodec, Debug, Clone)] +pub struct DataItemList { + #[len_repr(VAR::)] + items: Vec, +} From 32ef922b2886fc3530b1bf84d89915c39d877b79 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 04:42:17 +0800 Subject: [PATCH 08/22] rust fmt --- crates/proto/src/packets/add_actor_packet.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs index c0767ba4..b65afe8b 100644 --- a/crates/proto/src/packets/add_actor_packet.rs +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -6,7 +6,8 @@ use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; use crate::types::{ - actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, dataitem::DataItemList, property_sync_data::PropertySyncData + actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, + dataitem::DataItemList, property_sync_data::PropertySyncData, }; #[derive(ProtoCodec, Debug, Clone)] From a686606dc016940c54f5b6bdf5b808c3a141c5bc Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 22:27:51 +0800 Subject: [PATCH 09/22] Deleted unnecessary structures and used Rust-specific macros to handle some unimplemented things. --- crates/proto/src/packets/add_actor_packet.rs | 13 ++++++++----- crates/proto/src/types/actor_link.rs | 6 ------ crates/proto/src/types/actor_type.rs | 4 ++-- crates/proto/src/types/attribute.rs | 6 ------ crates/proto/src/types/dataitem.rs | 14 ++++---------- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs index b65afe8b..b25a51d7 100644 --- a/crates/proto/src/packets/add_actor_packet.rs +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -6,8 +6,8 @@ use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; use crate::types::{ - actor_link::ActorLinkList, actor_type::ActorType, attribute::AttributeList, - dataitem::DataItemList, property_sync_data::PropertySyncData, + actor_link::ActorLink, actor_type::ActorType, attribute::Attribute, dataitem::DataItem, + property_sync_data::PropertySyncData, }; #[derive(ProtoCodec, Debug, Clone)] @@ -20,8 +20,11 @@ pub struct AddActorPacket { pub rotation: Vec2>, pub y_head_rotation: LE, pub y_body_rotation: LE, - pub attributes: AttributeList, - pub actor_data: DataItemList, + #[len_repr(VAR::)] + pub attributes: Vec, + #[len_repr(VAR::)] + pub actor_data: Vec, pub synched_properties: PropertySyncData, - pub actor_links: ActorLinkList, + #[len_repr(VAR::)] + pub actor_links: Vec, } diff --git a/crates/proto/src/types/actor_link.rs b/crates/proto/src/types/actor_link.rs index b6bb5ec0..c3e29eb0 100644 --- a/crates/proto/src/types/actor_link.rs +++ b/crates/proto/src/types/actor_link.rs @@ -12,9 +12,3 @@ pub struct ActorLink { immediate: bool, passenger_seat_id: bool, } - -#[derive(ProtoCodec, Debug, Clone)] -pub struct ActorLinkList { - #[len_repr(VAR::)] - pub links: Vec, -} diff --git a/crates/proto/src/types/actor_type.rs b/crates/proto/src/types/actor_type.rs index 286f16ab..6acdb9e7 100644 --- a/crates/proto/src/types/actor_type.rs +++ b/crates/proto/src/types/actor_type.rs @@ -316,12 +316,12 @@ impl ProtoCodec for ActorType { &self, stream: &mut Vec, ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { - Ok(()) + unimplemented!() } fn proto_deserialize( stream: &mut std::io::Cursor<&[u8]>, ) -> Result { - Ok(Self::Pig) + unimplemented!() } } diff --git a/crates/proto/src/types/attribute.rs b/crates/proto/src/types/attribute.rs index e1236fcc..a4825a8b 100644 --- a/crates/proto/src/types/attribute.rs +++ b/crates/proto/src/types/attribute.rs @@ -8,9 +8,3 @@ pub struct Attribute { current: LE, max: LE, } - -#[derive(ProtoCodec, Debug, Clone)] -pub struct AttributeList { - #[len_repr(VAR::)] - attributes: Vec, -} diff --git a/crates/proto/src/types/dataitem.rs b/crates/proto/src/types/dataitem.rs index 90ccf6ae..bdb7f32a 100644 --- a/crates/proto/src/types/dataitem.rs +++ b/crates/proto/src/types/dataitem.rs @@ -6,12 +6,12 @@ use bedrockrs_nbt::NbtTag; use bedrockrs_proto_derive::ProtoCodec; #[derive(ProtoCodec, Debug, Clone)] -struct DataItem { +pub struct DataItem { id: VAR, value: DataItemValue, } #[derive(Debug, Clone)] -enum DataItemValue { +pub enum DataItemValue { ValByte(u8), ValShort(i16), ValInt(i32), @@ -28,18 +28,12 @@ impl ProtoCodec for DataItemValue { &self, stream: &mut Vec, ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { - Ok(()) + unimplemented!() } fn proto_deserialize( stream: &mut std::io::Cursor<&[u8]>, ) -> Result { - Ok(Self::ValByte(0)) + unimplemented!() } } - -#[derive(ProtoCodec, Debug, Clone)] -pub struct DataItemList { - #[len_repr(VAR::)] - items: Vec, -} From e21aa2680b2a023d4abdec1ae65d23b104c64a4d Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 22:30:41 +0800 Subject: [PATCH 10/22] Used Rust-specific macros to handle some unimplemented features. --- crates/proto/src/types/property_sync_data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs index 82de375f..9e125472 100644 --- a/crates/proto/src/types/property_sync_data.rs +++ b/crates/proto/src/types/property_sync_data.rs @@ -42,6 +42,6 @@ impl ProtoCodec for PropertySyncData { fn proto_deserialize( stream: &mut std::io::Cursor<&[u8]>, ) -> Result { - Ok(Self::Int(IntEntriesList::proto_deserialize(stream)?)) + unimplemented!() } } From 6eb84f59a687debdb33ba2fcb6c869258f30e3eb Mon Sep 17 00:00:00 2001 From: banchen19 Date: Mon, 5 Aug 2024 23:06:51 +0800 Subject: [PATCH 11/22] Used Rust-specific macros to handle some unimplemented features. --- crates/proto/src/types/attribute.rs | 8 ++++---- crates/proto/src/types/dataitem.rs | 4 ++-- crates/proto/src/types/property_sync_data.rs | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/proto/src/types/attribute.rs b/crates/proto/src/types/attribute.rs index a4825a8b..625e3dc1 100644 --- a/crates/proto/src/types/attribute.rs +++ b/crates/proto/src/types/attribute.rs @@ -3,8 +3,8 @@ use bedrockrs_proto_derive::ProtoCodec; #[derive(ProtoCodec, Debug, Clone)] pub struct Attribute { - name: String, - min: LE, - current: LE, - max: LE, + pub name: String, + pub min: LE, + pub current: LE, + pub max: LE, } diff --git a/crates/proto/src/types/dataitem.rs b/crates/proto/src/types/dataitem.rs index bdb7f32a..d238edd8 100644 --- a/crates/proto/src/types/dataitem.rs +++ b/crates/proto/src/types/dataitem.rs @@ -7,8 +7,8 @@ use bedrockrs_proto_derive::ProtoCodec; #[derive(ProtoCodec, Debug, Clone)] pub struct DataItem { - id: VAR, - value: DataItemValue, + pub id: VAR, + pub value: DataItemValue, } #[derive(Debug, Clone)] pub enum DataItemValue { diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs index 9e125472..47e61819 100644 --- a/crates/proto/src/types/property_sync_data.rs +++ b/crates/proto/src/types/property_sync_data.rs @@ -2,26 +2,26 @@ use bedrockrs_core::int::{LE, VAR}; use bedrockrs_proto_derive::ProtoCodec; #[derive(ProtoCodec, Debug, Clone)] -struct IntEntry { - index: VAR, - data: VAR, +pub struct IntEntry { + pub index: VAR, + pub data: VAR, } #[derive(ProtoCodec, Debug, Clone)] -struct IntEntriesList { +pub struct IntEntriesList { #[len_repr(VAR::)] - entries: Vec, + pub entries: Vec, } #[derive(ProtoCodec, Debug, Clone)] -struct FloatEntry { - index: VAR, - data: LE, +pub struct FloatEntry { + pub index: VAR, + pub data: LE, } #[derive(ProtoCodec, Debug, Clone)] -struct FloatEntriesList { +pub struct FloatEntriesList { #[len_repr(VAR::)] - entries: Vec, + pub entries: Vec, } #[derive(Debug, Clone)] From 31f6434817172e37883778c0b7e37858ee3f55be Mon Sep 17 00:00:00 2001 From: banchen19 Date: Tue, 6 Aug 2024 00:54:14 +0800 Subject: [PATCH 12/22] actor_type: String --- crates/proto/src/login/add_actor.rs | 63 ++++++++ crates/proto/src/login/handle.rs | 3 + crates/proto/src/login/mod.rs | 1 + crates/proto/src/packets/add_actor_packet.rs | 4 +- crates/proto/src/types/actor_type.rs | 158 +++++++++++++++++++ crates/proto/src/types/property_sync_data.rs | 6 +- 6 files changed, 230 insertions(+), 5 deletions(-) create mode 100644 crates/proto/src/login/add_actor.rs diff --git a/crates/proto/src/login/add_actor.rs b/crates/proto/src/login/add_actor.rs new file mode 100644 index 00000000..c325fc13 --- /dev/null +++ b/crates/proto/src/login/add_actor.rs @@ -0,0 +1,63 @@ +use bedrockrs_core::{int::LE, Vec2, Vec3}; +use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; + +use crate::{ + connection::ConnectionShard, + error::LoginError, + gamepacket::GamePacket, + packets::add_actor_packet::AddActorPacket, + types::{ + actor_type::ActorType, + property_sync_data::{FloatEntriesList, IntEntriesList, PropertySyncData}, + }, +}; + +use super::provider::LoginProviderServer; + +pub async fn add_actor( + conn: &mut ConnectionShard, + provider: &mut impl LoginProviderServer, +) -> Result<(), LoginError> { + ////////////////////////////////////// + // AddActorPacket + ////////////////////////////////////// + + let add_actor = AddActorPacket { + target_actor_id: ActorUniqueID(610), + target_runtime_id: ActorRuntimeID(403), + actor_type: String::from("minecraft:pig"), + position: Vec3 { + x: LE::new(4.0), + y: LE::new(8.0), + z: LE::new(7.0), + }, + velocity: Vec3 { + x: LE::new(4.0), + y: LE::new(8.0), + z: LE::new(7.0), + }, + rotation: Vec2 { + x: LE::new(270.0), + y: LE::new(90.0), + }, + y_head_rotation: LE::new(45.0), + y_body_rotation: LE::new(90.0), + attributes: vec![], + actor_data: vec![], + synched_properties: PropertySyncData { + int: IntEntriesList { entries: vec![] }, + float: FloatEntriesList { entries: vec![] }, + }, + actor_links: vec![], + }; + + conn.send(GamePacket::AddEntity(add_actor)) + .await + .map_err(|e| LoginError::ConnectionError(e))?; + + conn.flush() + .await + .map_err(|e| LoginError::ConnectionError(e))?; + + Ok(()) +} diff --git a/crates/proto/src/login/handle.rs b/crates/proto/src/login/handle.rs index b70ada5a..e3e30f92 100644 --- a/crates/proto/src/login/handle.rs +++ b/crates/proto/src/login/handle.rs @@ -8,6 +8,8 @@ use crate::login::play_status::play_status_login; use crate::login::provider::{LoginProviderClient, LoginProviderServer}; use crate::login::start_game::start_game; +use super::add_actor::add_actor; + pub async fn login_to_server( conn: &mut ConnectionShard, mut provider: impl LoginProviderServer, @@ -23,6 +25,7 @@ pub async fn login_to_server( start_game(conn, &mut provider).await?; + add_actor(conn, &mut provider).await?; Ok(()) } diff --git a/crates/proto/src/login/mod.rs b/crates/proto/src/login/mod.rs index 6bccfb49..7140c7db 100644 --- a/crates/proto/src/login/mod.rs +++ b/crates/proto/src/login/mod.rs @@ -1,5 +1,6 @@ pub use handle::*; +mod add_actor; pub mod handle; mod handshake; mod login; diff --git a/crates/proto/src/packets/add_actor_packet.rs b/crates/proto/src/packets/add_actor_packet.rs index b25a51d7..6536a0b7 100644 --- a/crates/proto/src/packets/add_actor_packet.rs +++ b/crates/proto/src/packets/add_actor_packet.rs @@ -6,7 +6,7 @@ use bedrockrs_proto_derive::ProtoCodec; use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID}; use crate::types::{ - actor_link::ActorLink, actor_type::ActorType, attribute::Attribute, dataitem::DataItem, + actor_link::ActorLink, attribute::Attribute, dataitem::DataItem, property_sync_data::PropertySyncData, }; @@ -14,7 +14,7 @@ use crate::types::{ pub struct AddActorPacket { pub target_actor_id: ActorUniqueID, pub target_runtime_id: ActorRuntimeID, - pub actor_type: ActorType, + pub actor_type: String, pub position: Vec3>, pub velocity: Vec3>, pub rotation: Vec2>, diff --git a/crates/proto/src/types/actor_type.rs b/crates/proto/src/types/actor_type.rs index 6acdb9e7..28a81347 100644 --- a/crates/proto/src/types/actor_type.rs +++ b/crates/proto/src/types/actor_type.rs @@ -311,6 +311,164 @@ pub enum ActorType { OminousItemSpawner = Flags::OMINOUSITEMSPAWNER.bits(), } +impl ActorType { + pub fn to_string(self) -> String { + match self { + ActorType::Player => "player".to_string(), + ActorType::ItemEntity => "item".to_string(), + ActorType::PrimedTnt => "tnt".to_string(), + ActorType::FallingBlock => "falling_block".to_string(), + ActorType::MovingBlock => "moving_block".to_string(), + ActorType::ExperiencePotion => "xp_orb".to_string(), + ActorType::Experience => "xp_bottle".to_string(), + ActorType::EyeOfEnder => "eye_of_ender_signal".to_string(), + ActorType::Undefined => todo!(), + ActorType::TypeMask => todo!(), + ActorType::Mob => todo!(), + ActorType::PathfinderMob => todo!(), + ActorType::Monster => todo!(), + ActorType::Animal => todo!(), + ActorType::TamableAnimal => todo!(), + ActorType::Ambient => todo!(), + ActorType::UndeadMob => todo!(), + ActorType::ZombieMonster => todo!(), + ActorType::Arthropod => todo!(), + ActorType::Minecart => todo!(), + ActorType::SkeletonMonster => todo!(), + ActorType::EquineAnimal => todo!(), + ActorType::Projectile => todo!(), + ActorType::AbstractArrow => todo!(), + ActorType::WaterAnimal => todo!(), + ActorType::VillagerBase => todo!(), + ActorType::Chicken => todo!(), + ActorType::Cow => todo!(), + ActorType::Pig => todo!(), + ActorType::Sheep => todo!(), + ActorType::Wolf => todo!(), + ActorType::Villager => todo!(), + ActorType::MushroomCow => todo!(), + ActorType::Squid => todo!(), + ActorType::Rabbit => todo!(), + ActorType::Bat => todo!(), + ActorType::IronGolem => todo!(), + ActorType::SnowGolem => todo!(), + ActorType::Ocelot => todo!(), + ActorType::Horse => todo!(), + ActorType::PolarBear => todo!(), + ActorType::Llama => todo!(), + ActorType::Parrot => todo!(), + ActorType::Dolphin => todo!(), + ActorType::Donkey => todo!(), + ActorType::Mule => todo!(), + ActorType::SkeletonHorse => todo!(), + ActorType::ZombieHorse => todo!(), + ActorType::Zombie => todo!(), + ActorType::Creeper => todo!(), + ActorType::Skeleton => todo!(), + ActorType::Spider => todo!(), + ActorType::PigZombie => todo!(), + ActorType::Slime => todo!(), + ActorType::EnderMan => todo!(), + ActorType::Silverfish => todo!(), + ActorType::CaveSpider => todo!(), + ActorType::Ghast => todo!(), + ActorType::LavaSlime => todo!(), + ActorType::Blaze => todo!(), + ActorType::ZombieVillager => todo!(), + ActorType::Witch => todo!(), + ActorType::Stray => todo!(), + ActorType::Husk => todo!(), + ActorType::WitherSkeleton => todo!(), + ActorType::Guardian => todo!(), + ActorType::ElderGuardian => todo!(), + ActorType::Npc => todo!(), + ActorType::WitherBoss => todo!(), + ActorType::Dragon => todo!(), + ActorType::Shulker => todo!(), + ActorType::Endermite => todo!(), + ActorType::Agent => todo!(), + ActorType::Vindicator => todo!(), + ActorType::Phantom => todo!(), + ActorType::IllagerBeast => todo!(), + ActorType::ArmorStand => todo!(), + ActorType::TripodCamera => todo!(), + ActorType::EnderCrystal => todo!(), + ActorType::FireworksRocket => todo!(), + ActorType::Trident => todo!(), + ActorType::Turtle => todo!(), + ActorType::Cat => todo!(), + ActorType::ShulkerBullet => todo!(), + ActorType::FishingHook => todo!(), + ActorType::Chalkboard => todo!(), + ActorType::DragonFireball => todo!(), + ActorType::Arrow => todo!(), + ActorType::Snowball => todo!(), + ActorType::ThrownEgg => todo!(), + ActorType::Painting => todo!(), + ActorType::LargeFireball => todo!(), + ActorType::ThrownPotion => todo!(), + ActorType::Enderpearl => todo!(), + ActorType::LeashKnot => todo!(), + ActorType::WitherSkull => todo!(), + ActorType::BoatRideable => todo!(), + ActorType::WitherSkullDangerous => todo!(), + ActorType::LightningBolt => todo!(), + ActorType::SmallFireball => todo!(), + ActorType::AreaEffectCloud => todo!(), + ActorType::LingeringPotion => todo!(), + ActorType::LlamaSpit => todo!(), + ActorType::EvocationFang => todo!(), + ActorType::EvocationIllager => todo!(), + ActorType::Vex => todo!(), + ActorType::MinecartRideable => todo!(), + ActorType::MinecartHopper => todo!(), + ActorType::MinecartTNT => todo!(), + ActorType::MinecartChest => todo!(), + ActorType::MinecartFurnace => todo!(), + ActorType::MinecartCommandBlock => todo!(), + ActorType::IceBomb => todo!(), + ActorType::Balloon => todo!(), + ActorType::Pufferfish => todo!(), + ActorType::Salmon => todo!(), + ActorType::Drowned => todo!(), + ActorType::Tropicalfish => todo!(), + ActorType::Fish => todo!(), + ActorType::Panda => todo!(), + ActorType::Pillager => todo!(), + ActorType::VillagerV2 => todo!(), + ActorType::ZombieVillagerV2 => todo!(), + ActorType::Shield => todo!(), + ActorType::WanderingTrader => todo!(), + ActorType::Lectern => todo!(), + ActorType::ElderGuardianGhost => todo!(), + ActorType::Fox => todo!(), + ActorType::Bee => todo!(), + ActorType::Piglin => todo!(), + ActorType::Hoglin => todo!(), + ActorType::Strider => todo!(), + ActorType::Zoglin => todo!(), + ActorType::PiglinBrute => todo!(), + ActorType::Goat => todo!(), + ActorType::GlowSquid => todo!(), + ActorType::Axolotl => todo!(), + ActorType::Warden => todo!(), + ActorType::Frog => todo!(), + ActorType::Tadpole => todo!(), + ActorType::Allay => todo!(), + ActorType::ChestBoatRideable => todo!(), + ActorType::TraderLlama => todo!(), + ActorType::Camel => todo!(), + ActorType::Sniffer => todo!(), + ActorType::Breeze => todo!(), + ActorType::BreezeWindChargeProjectile => todo!(), + ActorType::Armadillo => todo!(), + ActorType::WindChargeProjectile => todo!(), + ActorType::Bogged => todo!(), + ActorType::OminousItemSpawner => todo!(), + } + } +} + impl ProtoCodec for ActorType { fn proto_serialize( &self, diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs index 47e61819..3851ab1f 100644 --- a/crates/proto/src/types/property_sync_data.rs +++ b/crates/proto/src/types/property_sync_data.rs @@ -25,9 +25,9 @@ pub struct FloatEntriesList { } #[derive(Debug, Clone)] -pub enum PropertySyncData { - Int(IntEntriesList), - Float(FloatEntriesList), +pub struct PropertySyncData { + pub int: IntEntriesList, + pub float: FloatEntriesList, } use bedrockrs_proto_core::ProtoCodec; From f557b2639e82d5cd02e2a420566248911d29ee75 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Tue, 6 Aug 2024 02:08:52 +0800 Subject: [PATCH 13/22] delete impl ProtoCodec for PropertySyncData --- crates/proto/src/types/property_sync_data.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/crates/proto/src/types/property_sync_data.rs b/crates/proto/src/types/property_sync_data.rs index 3851ab1f..f388e4e5 100644 --- a/crates/proto/src/types/property_sync_data.rs +++ b/crates/proto/src/types/property_sync_data.rs @@ -24,24 +24,8 @@ pub struct FloatEntriesList { pub entries: Vec, } -#[derive(Debug, Clone)] +#[derive(ProtoCodec, Debug, Clone)] pub struct PropertySyncData { pub int: IntEntriesList, pub float: FloatEntriesList, } - -use bedrockrs_proto_core::ProtoCodec; -impl ProtoCodec for PropertySyncData { - fn proto_serialize( - &self, - stream: &mut Vec, - ) -> Result<(), bedrockrs_proto_core::error::ProtoCodecError> { - Ok(()) - } - - fn proto_deserialize( - stream: &mut std::io::Cursor<&[u8]>, - ) -> Result { - unimplemented!() - } -} From 4ca659006295f4cfa67f67b16176af2f50c05f98 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Tue, 6 Aug 2024 23:28:59 +0800 Subject: [PATCH 14/22] add ActorType fn to_string --- crates/proto/src/login/add_actor.rs | 4 +- crates/proto/src/login/handle.rs | 2 - crates/proto/src/types/actor_type.rs | 302 +++++++++++++-------------- 3 files changed, 153 insertions(+), 155 deletions(-) diff --git a/crates/proto/src/login/add_actor.rs b/crates/proto/src/login/add_actor.rs index c325fc13..98341ced 100644 --- a/crates/proto/src/login/add_actor.rs +++ b/crates/proto/src/login/add_actor.rs @@ -19,13 +19,13 @@ pub async fn add_actor( provider: &mut impl LoginProviderServer, ) -> Result<(), LoginError> { ////////////////////////////////////// - // AddActorPacket + // todo: AddActorPacket ////////////////////////////////////// let add_actor = AddActorPacket { target_actor_id: ActorUniqueID(610), target_runtime_id: ActorRuntimeID(403), - actor_type: String::from("minecraft:pig"), + actor_type: ActorType::Pig.to_string(), position: Vec3 { x: LE::new(4.0), y: LE::new(8.0), diff --git a/crates/proto/src/login/handle.rs b/crates/proto/src/login/handle.rs index e3e30f92..05fd0628 100644 --- a/crates/proto/src/login/handle.rs +++ b/crates/proto/src/login/handle.rs @@ -24,8 +24,6 @@ pub async fn login_to_server( packs(conn, &mut provider).await?; start_game(conn, &mut provider).await?; - - add_actor(conn, &mut provider).await?; Ok(()) } diff --git a/crates/proto/src/types/actor_type.rs b/crates/proto/src/types/actor_type.rs index 28a81347..959222d8 100644 --- a/crates/proto/src/types/actor_type.rs +++ b/crates/proto/src/types/actor_type.rs @@ -314,157 +314,157 @@ pub enum ActorType { impl ActorType { pub fn to_string(self) -> String { match self { - ActorType::Player => "player".to_string(), - ActorType::ItemEntity => "item".to_string(), - ActorType::PrimedTnt => "tnt".to_string(), - ActorType::FallingBlock => "falling_block".to_string(), - ActorType::MovingBlock => "moving_block".to_string(), - ActorType::ExperiencePotion => "xp_orb".to_string(), - ActorType::Experience => "xp_bottle".to_string(), - ActorType::EyeOfEnder => "eye_of_ender_signal".to_string(), - ActorType::Undefined => todo!(), - ActorType::TypeMask => todo!(), - ActorType::Mob => todo!(), - ActorType::PathfinderMob => todo!(), - ActorType::Monster => todo!(), - ActorType::Animal => todo!(), - ActorType::TamableAnimal => todo!(), - ActorType::Ambient => todo!(), - ActorType::UndeadMob => todo!(), - ActorType::ZombieMonster => todo!(), - ActorType::Arthropod => todo!(), - ActorType::Minecart => todo!(), - ActorType::SkeletonMonster => todo!(), - ActorType::EquineAnimal => todo!(), - ActorType::Projectile => todo!(), - ActorType::AbstractArrow => todo!(), - ActorType::WaterAnimal => todo!(), - ActorType::VillagerBase => todo!(), - ActorType::Chicken => todo!(), - ActorType::Cow => todo!(), - ActorType::Pig => todo!(), - ActorType::Sheep => todo!(), - ActorType::Wolf => todo!(), - ActorType::Villager => todo!(), - ActorType::MushroomCow => todo!(), - ActorType::Squid => todo!(), - ActorType::Rabbit => todo!(), - ActorType::Bat => todo!(), - ActorType::IronGolem => todo!(), - ActorType::SnowGolem => todo!(), - ActorType::Ocelot => todo!(), - ActorType::Horse => todo!(), - ActorType::PolarBear => todo!(), - ActorType::Llama => todo!(), - ActorType::Parrot => todo!(), - ActorType::Dolphin => todo!(), - ActorType::Donkey => todo!(), - ActorType::Mule => todo!(), - ActorType::SkeletonHorse => todo!(), - ActorType::ZombieHorse => todo!(), - ActorType::Zombie => todo!(), - ActorType::Creeper => todo!(), - ActorType::Skeleton => todo!(), - ActorType::Spider => todo!(), - ActorType::PigZombie => todo!(), - ActorType::Slime => todo!(), - ActorType::EnderMan => todo!(), - ActorType::Silverfish => todo!(), - ActorType::CaveSpider => todo!(), - ActorType::Ghast => todo!(), - ActorType::LavaSlime => todo!(), - ActorType::Blaze => todo!(), - ActorType::ZombieVillager => todo!(), - ActorType::Witch => todo!(), - ActorType::Stray => todo!(), - ActorType::Husk => todo!(), - ActorType::WitherSkeleton => todo!(), - ActorType::Guardian => todo!(), - ActorType::ElderGuardian => todo!(), - ActorType::Npc => todo!(), - ActorType::WitherBoss => todo!(), - ActorType::Dragon => todo!(), - ActorType::Shulker => todo!(), - ActorType::Endermite => todo!(), - ActorType::Agent => todo!(), - ActorType::Vindicator => todo!(), - ActorType::Phantom => todo!(), - ActorType::IllagerBeast => todo!(), - ActorType::ArmorStand => todo!(), - ActorType::TripodCamera => todo!(), - ActorType::EnderCrystal => todo!(), - ActorType::FireworksRocket => todo!(), - ActorType::Trident => todo!(), - ActorType::Turtle => todo!(), - ActorType::Cat => todo!(), - ActorType::ShulkerBullet => todo!(), - ActorType::FishingHook => todo!(), - ActorType::Chalkboard => todo!(), - ActorType::DragonFireball => todo!(), - ActorType::Arrow => todo!(), - ActorType::Snowball => todo!(), - ActorType::ThrownEgg => todo!(), - ActorType::Painting => todo!(), - ActorType::LargeFireball => todo!(), - ActorType::ThrownPotion => todo!(), - ActorType::Enderpearl => todo!(), - ActorType::LeashKnot => todo!(), - ActorType::WitherSkull => todo!(), - ActorType::BoatRideable => todo!(), - ActorType::WitherSkullDangerous => todo!(), - ActorType::LightningBolt => todo!(), - ActorType::SmallFireball => todo!(), - ActorType::AreaEffectCloud => todo!(), - ActorType::LingeringPotion => todo!(), - ActorType::LlamaSpit => todo!(), - ActorType::EvocationFang => todo!(), - ActorType::EvocationIllager => todo!(), - ActorType::Vex => todo!(), - ActorType::MinecartRideable => todo!(), - ActorType::MinecartHopper => todo!(), - ActorType::MinecartTNT => todo!(), - ActorType::MinecartChest => todo!(), - ActorType::MinecartFurnace => todo!(), - ActorType::MinecartCommandBlock => todo!(), - ActorType::IceBomb => todo!(), - ActorType::Balloon => todo!(), - ActorType::Pufferfish => todo!(), - ActorType::Salmon => todo!(), - ActorType::Drowned => todo!(), - ActorType::Tropicalfish => todo!(), - ActorType::Fish => todo!(), - ActorType::Panda => todo!(), - ActorType::Pillager => todo!(), - ActorType::VillagerV2 => todo!(), - ActorType::ZombieVillagerV2 => todo!(), - ActorType::Shield => todo!(), - ActorType::WanderingTrader => todo!(), - ActorType::Lectern => todo!(), - ActorType::ElderGuardianGhost => todo!(), - ActorType::Fox => todo!(), - ActorType::Bee => todo!(), - ActorType::Piglin => todo!(), - ActorType::Hoglin => todo!(), - ActorType::Strider => todo!(), - ActorType::Zoglin => todo!(), - ActorType::PiglinBrute => todo!(), - ActorType::Goat => todo!(), - ActorType::GlowSquid => todo!(), - ActorType::Axolotl => todo!(), - ActorType::Warden => todo!(), - ActorType::Frog => todo!(), - ActorType::Tadpole => todo!(), - ActorType::Allay => todo!(), - ActorType::ChestBoatRideable => todo!(), - ActorType::TraderLlama => todo!(), - ActorType::Camel => todo!(), - ActorType::Sniffer => todo!(), - ActorType::Breeze => todo!(), - ActorType::BreezeWindChargeProjectile => todo!(), - ActorType::Armadillo => todo!(), - ActorType::WindChargeProjectile => todo!(), - ActorType::Bogged => todo!(), - ActorType::OminousItemSpawner => todo!(), + ActorType::Undefined => unimplemented!(), + ActorType::TypeMask => unimplemented!(), + ActorType::Mob => unimplemented!(), + ActorType::PathfinderMob => unimplemented!(), + ActorType::Monster => unimplemented!(), + ActorType::Animal => unimplemented!(), + ActorType::TamableAnimal => unimplemented!(), + ActorType::Ambient => unimplemented!(), + ActorType::UndeadMob => unimplemented!(), + ActorType::ZombieMonster => unimplemented!(), + ActorType::Arthropod => unimplemented!(), + ActorType::Minecart => String::from("minecraft:minecart"), + ActorType::SkeletonMonster => unimplemented!(), + ActorType::EquineAnimal => unimplemented!(), + ActorType::Projectile => unimplemented!(), + ActorType::AbstractArrow => unimplemented!(), + ActorType::WaterAnimal => unimplemented!(), + ActorType::VillagerBase => unimplemented!(), + ActorType::Chicken => String::from("minecraft:chicken"), + ActorType::Cow => String::from("minecraft:cow"), + ActorType::Pig => String::from("minecraft:pig"), + ActorType::Sheep => String::from("minecraft:sheep"), + ActorType::Wolf => String::from("minecraft:wolf"), + ActorType::Villager => String::from("minecraft:villager"), + ActorType::MushroomCow => unimplemented!(), + ActorType::Squid => String::from("minecraft:squid"), + ActorType::Rabbit => String::from("minecraft:rabbit"), + ActorType::Bat => String::from("minecraft:bat"), + ActorType::IronGolem => String::from("minecraft:iron_golem"), + ActorType::SnowGolem => String::from("minecraft:snow_golem"), + ActorType::Ocelot => String::from("minecraft:ocelot"), + ActorType::Horse => String::from("minecraft:zombie_horse"), + ActorType::PolarBear => String::from("minecraft:polar_bear"), + ActorType::Llama => String::from("minecraft:llama_spit"), + ActorType::Parrot => String::from("minecraft:parrot"), + ActorType::Dolphin => String::from("minecraft:dolphin"), + ActorType::Donkey => String::from("minecraft:donkey"), + ActorType::Mule => String::from("minecraft:mule"), + ActorType::SkeletonHorse => String::from("minecraft:skeleton_horse"), + ActorType::ZombieHorse => String::from("minecraft:zombie_horse"), + ActorType::Zombie => String::from("minecraft:zombie"), + ActorType::Creeper => String::from("minecraft:creeper"), + ActorType::Skeleton => String::from("minecraft:skeleton"), + ActorType::Spider => String::from("minecraft:spider"), + ActorType::PigZombie => unimplemented!(), + ActorType::Slime => String::from("minecraft:slime"), + ActorType::EnderMan => String::from("minecraft:enderman"), + ActorType::Silverfish => String::from("minecraft:silverfish"), + ActorType::CaveSpider => String::from("minecraft:cave_spider"), + ActorType::Ghast => String::from("minecraft:ghast"), + ActorType::LavaSlime => String::from("minecraft:magma_cube"), + ActorType::Blaze => String::from("minecraft:blaze"), + ActorType::ZombieVillager => String::from("minecraft:zombie_villager"), + ActorType::Witch => String::from("minecraft:witch"), + ActorType::Stray => String::from("minecraft:stray"), + ActorType::Husk => String::from("minecraft:husk"), + ActorType::WitherSkeleton => String::from("minecraft:wither_skeleton"), + ActorType::Guardian => String::from("minecraft:guardian"), + ActorType::ElderGuardian => String::from("minecraft:elder_guardian"), + ActorType::Npc => String::from("minecraft:npc"), + ActorType::WitherBoss => unimplemented!(), + ActorType::Dragon => unimplemented!(), + ActorType::Shulker => String::from("minecraft:shulker"), + ActorType::Endermite => String::from("minecraft:endermite"), + ActorType::Agent => String::from("minecraft:agent"), + ActorType::Vindicator => String::from("minecraft:vindicator"), + ActorType::Phantom => String::from("minecraft:phantom"), + ActorType::IllagerBeast => unimplemented!(), + ActorType::ArmorStand => String::from("minecraft:armor_stand"), + ActorType::TripodCamera => unimplemented!(), + ActorType::Player => String::from("minecraft:player"), + ActorType::ItemEntity => unimplemented!(), + ActorType::PrimedTnt => String::from("minecraft:tnt"), + ActorType::FallingBlock => String::from("minecraft:falling_block"), + ActorType::MovingBlock => unimplemented!(), + ActorType::ExperiencePotion => unimplemented!(), + ActorType::Experience => unimplemented!(), + ActorType::EyeOfEnder => unimplemented!(), + ActorType::EnderCrystal => unimplemented!(), + ActorType::FireworksRocket => unimplemented!(), + ActorType::Trident => unimplemented!(), + ActorType::Turtle => String::from("minecraft:turtle"), + ActorType::Cat => String::from("minecraft:cat"), + ActorType::ShulkerBullet => String::from("minecraft:shulker_bullet"), + ActorType::FishingHook => String::from("minecraft:fishing_hook"), + ActorType::Chalkboard => unimplemented!(), + ActorType::DragonFireball => unimplemented!(), + ActorType::Arrow => String::from("minecraft:arrow"), + ActorType::Snowball => String::from("minecraft:snowball"), + ActorType::ThrownEgg => unimplemented!(), + ActorType::Painting => String::from("minecraft:painting"), + ActorType::LargeFireball => unimplemented!(), + ActorType::ThrownPotion => unimplemented!(), + ActorType::Enderpearl => String::from("minecraft:ender_pearl"), + ActorType::LeashKnot => unimplemented!(), + ActorType::WitherSkull => String::from("minecraft:wither_skull"), + ActorType::BoatRideable => unimplemented!(), + ActorType::WitherSkullDangerous => unimplemented!(), + ActorType::LightningBolt => unimplemented!(), + ActorType::SmallFireball => String::from("minecraft:small_fireball"), + ActorType::AreaEffectCloud => String::from("minecraft:area_effect_cloud"), + ActorType::LingeringPotion => unimplemented!(), + ActorType::LlamaSpit => String::from("minecraft:llama_spit"), + ActorType::EvocationFang => String::from("minecraft:evocation_fang"), + ActorType::EvocationIllager => unimplemented!(), + ActorType::Vex => String::from("minecraft:vex"), + ActorType::MinecartRideable => unimplemented!(), + ActorType::MinecartHopper => String::from("minecraft:hopper_minecart"), + ActorType::MinecartTNT => String::from("minecraft:tnt_minecart"), + ActorType::MinecartChest => String::from("minecraft:chest_minecart"), + ActorType::MinecartFurnace => unimplemented!(), + ActorType::MinecartCommandBlock => unimplemented!(), + ActorType::IceBomb => unimplemented!(), + ActorType::Balloon => String::from("minecraft:balloon"), + ActorType::Pufferfish => String::from("minecraft:pufferfish"), + ActorType::Salmon => String::from("minecraft:salmon"), + ActorType::Drowned => String::from("minecraft:drowned"), + ActorType::Tropicalfish => String::from("minecraft:tropicalfish"), + ActorType::Fish => unimplemented!(), + ActorType::Panda => String::from("minecraft:panda"), + ActorType::Pillager => String::from("minecraft:pillager"), + ActorType::VillagerV2 => String::from("minecraft:villager_v2"), + ActorType::ZombieVillagerV2 => String::from("minecraft:zombie_villager_v2"), + ActorType::Shield => unimplemented!(), + ActorType::WanderingTrader => String::from("minecraft:wandering_trader"), + ActorType::Lectern => unimplemented!(), + ActorType::ElderGuardianGhost => unimplemented!(), + ActorType::Fox => String::from("minecraft:fox"), + ActorType::Bee => String::from("minecraft:bee"), + ActorType::Piglin => String::from("minecraft:piglin"), + ActorType::Hoglin => String::from("minecraft:hoglin"), + ActorType::Strider => String::from("minecraft:strider"), + ActorType::Zoglin => String::from("minecraft:zoglin"), + ActorType::PiglinBrute => String::from("minecraft:piglin_brute"), + ActorType::Goat => String::from("minecraft:goat"), + ActorType::GlowSquid => String::from("minecraft:glow_squid"), + ActorType::Axolotl => String::from("minecraft:axolotl"), + ActorType::Warden => String::from("minecraft:warden"), + ActorType::Frog => String::from("minecraft:frog"), + ActorType::Tadpole => String::from("minecraft:tadpole"), + ActorType::Allay => String::from("minecraft:allay"), + ActorType::ChestBoatRideable => unimplemented!(), + ActorType::TraderLlama => unimplemented!(), + ActorType::Camel => String::from("minecraft:camel"), + ActorType::Sniffer => unimplemented!(), + ActorType::Breeze => unimplemented!(), + ActorType::BreezeWindChargeProjectile => unimplemented!(), + ActorType::Armadillo => unimplemented!(), + ActorType::WindChargeProjectile => unimplemented!(), + ActorType::Bogged => unimplemented!(), + ActorType::OminousItemSpawner => unimplemented!(), } } } From c6941640c502a0c1027baba21cd3198df9eb4f32 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Tue, 6 Aug 2024 23:39:22 +0800 Subject: [PATCH 15/22] cargo fmt --- crates/proto/src/login/start_game.rs | 4 +--- crates/proto/src/packets/network_settings.rs | 2 +- crates/proto/src/packets/text_message.rs | 21 +++++++++++++++---- .../proto/src/transport_layer/connection.rs | 1 - crates/proto/src/types/connection_request.rs | 11 +++++----- crates/proto_derive/src/de.rs | 11 +++++----- crates/proto_derive/src/ser.rs | 9 ++++---- crates/world/src/level_dat/level_dat.rs | 5 ++--- crates/world/src/world_db/world_db.rs | 8 +++---- 9 files changed, 40 insertions(+), 32 deletions(-) diff --git a/crates/proto/src/login/start_game.rs b/crates/proto/src/login/start_game.rs index 85fa9574..c6679523 100644 --- a/crates/proto/src/login/start_game.rs +++ b/crates/proto/src/login/start_game.rs @@ -155,9 +155,7 @@ pub async fn start_game( })) .await .map_err(LoginError::ConnectionError)?; - conn.flush() - .await - .map_err(LoginError::ConnectionError)?; + conn.flush().await.map_err(LoginError::ConnectionError)?; Ok(()) } diff --git a/crates/proto/src/packets/network_settings.rs b/crates/proto/src/packets/network_settings.rs index c1a887c8..20972277 100644 --- a/crates/proto/src/packets/network_settings.rs +++ b/crates/proto/src/packets/network_settings.rs @@ -12,7 +12,7 @@ pub struct NetworkSettingsPacket { /// - 0x0000 is Zlib /// - 0x0001 is Snappy /// - 0xFFFF is No compression - /// + /// /// All 3 compression Algorithms are supported pub compression_algorithm: LE, pub client_throttle_enabled: bool, diff --git a/crates/proto/src/packets/text_message.rs b/crates/proto/src/packets/text_message.rs index 1c34feb4..cf3cbeb6 100644 --- a/crates/proto/src/packets/text_message.rs +++ b/crates/proto/src/packets/text_message.rs @@ -50,7 +50,11 @@ impl ProtoCodec for TextMessagePacket { } => { message.proto_serialize(stream)?; - let len = VAR::::new(Vec::len(¶meters).try_into().map_err(ProtoCodecError::FromIntError)?); + let len = VAR::::new( + Vec::len(¶meters) + .try_into() + .map_err(ProtoCodecError::FromIntError)?, + ); len.proto_serialize(stream)?; for parameter in parameters { @@ -63,7 +67,11 @@ impl ProtoCodec for TextMessagePacket { } => { message.proto_serialize(stream)?; - let len = VAR::::new(Vec::len(¶meters).try_into().map_err(ProtoCodecError::FromIntError)?); + let len = VAR::::new( + Vec::len(¶meters) + .try_into() + .map_err(ProtoCodecError::FromIntError)?, + ); len.proto_serialize(stream)?; for parameter in parameters { @@ -76,7 +84,11 @@ impl ProtoCodec for TextMessagePacket { } => { message.proto_serialize(stream)?; - let len = VAR::::new(Vec::len(¶meters).try_into().map_err(ProtoCodecError::FromIntError)?); + let len = VAR::::new( + Vec::len(¶meters) + .try_into() + .map_err(ProtoCodecError::FromIntError)?, + ); len.proto_serialize(stream)?; for parameter in parameters { @@ -153,7 +165,8 @@ impl ProtoCodec for TextMessagePacket { let message = String::proto_deserialize(stream)?; let len = VAR::::proto_deserialize(stream)?.into_inner(); - let mut parameters = Vec::with_capacity(len.try_into().map_err(ProtoCodecError::FromIntError)?); + let mut parameters = + Vec::with_capacity(len.try_into().map_err(ProtoCodecError::FromIntError)?); for _ in 0..len { parameters.push(String::proto_deserialize(stream)?); diff --git a/crates/proto/src/transport_layer/connection.rs b/crates/proto/src/transport_layer/connection.rs index e77de666..bc3e901f 100644 --- a/crates/proto/src/transport_layer/connection.rs +++ b/crates/proto/src/transport_layer/connection.rs @@ -6,7 +6,6 @@ use bedrockrs_core::int::LE; use crate::error::{RaknetError, TransportLayerError}; use crate::info::RAKNET_GAME_PACKET_ID; - pub enum TransportLayerConnection { RaknetUDP(rak_rs::connection::Connection), // TODO RaknetTCP(...), diff --git a/crates/proto/src/types/connection_request.rs b/crates/proto/src/types/connection_request.rs index e11aace1..827359f8 100644 --- a/crates/proto/src/types/connection_request.rs +++ b/crates/proto/src/types/connection_request.rs @@ -167,8 +167,8 @@ impl ProtoCodec for ConnectionRequest { }; // Extract header - let jwt_header = jsonwebtoken::decode_header(&jwt_string) - .map_err(ProtoCodecError::JwtError)?; + let jwt_header = + jsonwebtoken::decode_header(&jwt_string).map_err(ProtoCodecError::JwtError)?; let mut jwt_validation = Validation::new(jwt_header.alg); // TODO: This definitely is not right. Even Zuri-MC doesn't understand this.. I may understand it.. I do understand it, update I don't. @@ -232,12 +232,11 @@ impl ProtoCodec for ConnectionRequest { // transform into string let raw_token_string = - String::from_utf8(raw_token_buf) - .map_err(ProtoCodecError::UTF8Error)?; + String::from_utf8(raw_token_buf).map_err(ProtoCodecError::UTF8Error)?; // Extract header - let raw_token_jwt_header = jsonwebtoken::decode_header(&raw_token_string) - .map_err(ProtoCodecError::JwtError)?; + let raw_token_jwt_header = + jsonwebtoken::decode_header(&raw_token_string).map_err(ProtoCodecError::JwtError)?; let mut jwt_validation = Validation::new(raw_token_jwt_header.alg); // TODO: This definitely is not right. Even Zuri-MC doesn't understand this.. I may understand it.. I do understand it, update I don't. diff --git a/crates/proto_derive/src/de.rs b/crates/proto_derive/src/de.rs index 81819973..cf89dcc9 100644 --- a/crates/proto_derive/src/de.rs +++ b/crates/proto_derive/src/de.rs @@ -138,10 +138,10 @@ pub fn proto_build_de_enum( for attr in attributes { if attr.path().is_ident("enum_repr") { - int_type = Some( - attr.parse_args() - .unwrap_or_else(|_| panic!("Given attribute meta for enum could not be parsed")), - ); + int_type = + Some(attr.parse_args().unwrap_or_else(|_| { + panic!("Given attribute meta for enum could not be parsed") + })); } } @@ -149,7 +149,8 @@ pub fn proto_build_de_enum( .unwrap_or_else(|| panic!("Missing attribute \"enum_repr\" for ProtoCodec macro on Enum")); let calls = enum_data.variants.iter().map(|v| { - let val = v.discriminant + let val = v + .discriminant .clone() .unwrap_or_else(|| panic!("Discriminant needed")) .1; diff --git a/crates/proto_derive/src/ser.rs b/crates/proto_derive/src/ser.rs index e5fa919a..47eee59b 100644 --- a/crates/proto_derive/src/ser.rs +++ b/crates/proto_derive/src/ser.rs @@ -128,11 +128,10 @@ pub fn proto_build_ser_enum( for attr in attributes { if attr.path().is_ident("enum_repr") { - int_type = Some( - attr - .parse_args() - .unwrap_or_else(|_| panic!("Given attribute meta for enum could not be parsed")), - ); + int_type = + Some(attr.parse_args().unwrap_or_else(|_| { + panic!("Given attribute meta for enum could not be parsed") + })); } } diff --git a/crates/world/src/level_dat/level_dat.rs b/crates/world/src/level_dat/level_dat.rs index 5b593929..6f1894e7 100644 --- a/crates/world/src/level_dat/level_dat.rs +++ b/crates/world/src/level_dat/level_dat.rs @@ -78,9 +78,8 @@ impl LevelDat { pub fn open(directory: &Path) -> Result<(i32, i32, Self), WorldError> { // Open the level.dat file // TODO find out why there is a level.dat_old file as well and how it can be utilised - let mut file = File::open(directory.join("level.dat")).map_err(|e| { - WorldError::FormatError(e.to_string()) - })?; + let mut file = File::open(directory.join("level.dat")) + .map_err(|e| WorldError::FormatError(e.to_string()))?; // Read the entire level.dat file let mut data = vec![]; diff --git a/crates/world/src/world_db/world_db.rs b/crates/world/src/world_db/world_db.rs index 4cebffc6..9821f4ed 100644 --- a/crates/world/src/world_db/world_db.rs +++ b/crates/world/src/world_db/world_db.rs @@ -1,8 +1,8 @@ -use std::fmt::{Debug, Formatter}; -use std::{collections::HashMap, path::PathBuf}; -use std::path::Path; use bedrockrs_nbt::{endian::little_endian::NbtLittleEndian, NbtTag}; use mojang_leveldb::{error::DBError, Options, ReadOptions, WriteBatch, WriteOptions, DB}; +use std::fmt::{Debug, Formatter}; +use std::path::Path; +use std::{collections::HashMap, path::PathBuf}; use uuid::Uuid; use bedrockrs_shared::world::dimension::Dimension; @@ -100,7 +100,7 @@ impl WorldDB { READ_OPTIONS, create_key(x, z, dimension, RecordType::SubChunkPrefix { y }).as_slice(), )?; - + Ok(bytes.map(|x| SubChunk::load(&(x.get())))) } From 2d559c69e659b2d99a8758bbc799af08f36f6f49 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Wed, 7 Aug 2024 01:37:54 +0800 Subject: [PATCH 16/22] add settitle datapacket --- crates/proto/src/gamepacket.rs | 11 +++--- crates/proto/src/login/handle.rs | 2 + crates/proto/src/login/mod.rs | 1 + crates/proto/src/login/set_title.rs | 41 ++++++++++++++++++++ crates/proto/src/packets/mod.rs | 1 + crates/proto/src/packets/set_title_packet.rs | 15 +++++++ crates/proto/src/types/mod.rs | 1 + crates/proto/src/types/title_type.rs | 16 ++++++++ 8 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 crates/proto/src/login/set_title.rs create mode 100644 crates/proto/src/packets/set_title_packet.rs create mode 100644 crates/proto/src/types/title_type.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 60ca46fa..96ce0246 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -29,6 +29,7 @@ use crate::packets::resource_packs_stack::ResourcePacksStackPacket; 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_title_packet::SetTitlePacket; use crate::packets::start_game::StartGamePacket; use crate::packets::text_message::TextMessagePacket; use bedrockrs_core::int::VAR; @@ -123,7 +124,7 @@ pub enum GamePacket { Transfer(), PlaySound(), StopSound(), - SetTitle(), + SetTitle(SetTitlePacket), AddBehaviorTree(), StructureBlockUpdate(), ShowStoreOffer(), @@ -650,8 +651,8 @@ impl GamePacket { GamePacket::StopSound() => { unimplemented!() } - GamePacket::SetTitle() => { - unimplemented!() + GamePacket::SetTitle(pk) => { + ser_packet!(stream, GamePacket::SetTitleID, pk) } GamePacket::AddBehaviorTree() => { unimplemented!() @@ -1115,9 +1116,7 @@ impl GamePacket { GamePacket::StopSoundID => { unimplemented!() } - GamePacket::SetTitleID => { - unimplemented!() - } + GamePacket::SetTitleID => GamePacket::SetTitle(de_packet!(stream, SetTitlePacket)), GamePacket::AddBehaviorTreeID => { unimplemented!() } diff --git a/crates/proto/src/login/handle.rs b/crates/proto/src/login/handle.rs index 05fd0628..f01d84b2 100644 --- a/crates/proto/src/login/handle.rs +++ b/crates/proto/src/login/handle.rs @@ -9,6 +9,7 @@ use crate::login::provider::{LoginProviderClient, LoginProviderServer}; use crate::login::start_game::start_game; use super::add_actor::add_actor; +use super::set_title::set_title; pub async fn login_to_server( conn: &mut ConnectionShard, @@ -24,6 +25,7 @@ pub async fn login_to_server( packs(conn, &mut provider).await?; start_game(conn, &mut provider).await?; + set_title(conn, &mut provider).await?; Ok(()) } diff --git a/crates/proto/src/login/mod.rs b/crates/proto/src/login/mod.rs index 7140c7db..2145c0f3 100644 --- a/crates/proto/src/login/mod.rs +++ b/crates/proto/src/login/mod.rs @@ -8,4 +8,5 @@ mod network_settings; mod packs; mod play_status; pub mod provider; +mod set_title; mod start_game; diff --git a/crates/proto/src/login/set_title.rs b/crates/proto/src/login/set_title.rs new file mode 100644 index 00000000..f9cb2159 --- /dev/null +++ b/crates/proto/src/login/set_title.rs @@ -0,0 +1,41 @@ +use bedrockrs_core::int::VAR; + +use crate::connection::ConnectionShard; +use crate::error::LoginError; +use crate::gamepacket::GamePacket; +use crate::login::provider::{LoginProviderServer, LoginProviderStatus}; +use crate::packets::play_status::PlayStatusPacket; +use crate::packets::set_title_packet::SetTitlePacket; +use crate::types::play_status::PlayStatusType; +use crate::types::title_type::TitleType; + +pub async fn set_title( + conn: &mut ConnectionShard, + provider: &mut impl LoginProviderServer, +) -> Result<(), LoginError> { + ////////////////////////////////////// + // Set Title + ////////////////////////////////////// + + let set_title = SetTitlePacket { + title_type: TitleType::Title, + title_text: String::from("hello_text"), + fade_in_time: VAR::new(500), + stay_time: VAR::new(500), + fade_out_time: VAR::new(500), + xuid: String::from("hello_xuid"), + platform_online_id: String::from("hello_platform_online_id"), + }; + + match conn.send(GamePacket::SetTitle(set_title)).await { + Ok(_) => {} + Err(e) => return Err(LoginError::ConnectionError(e)), + } + + match conn.flush().await { + Ok(_) => {} + Err(e) => return Err(LoginError::ConnectionError(e)), + }; + + Ok(()) +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index 0dbe2b09..4e095167 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -24,5 +24,6 @@ pub mod resource_packs_stack; pub mod server_settings_request; pub mod server_settings_response; pub mod set_local_player_as_initialized; +pub mod set_title_packet; pub mod start_game; pub mod text_message; diff --git a/crates/proto/src/packets/set_title_packet.rs b/crates/proto/src/packets/set_title_packet.rs new file mode 100644 index 00000000..3a8cd8a4 --- /dev/null +++ b/crates/proto/src/packets/set_title_packet.rs @@ -0,0 +1,15 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +use crate::types::title_type::TitleType; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct SetTitlePacket { + pub title_type: TitleType, + pub title_text: String, + pub fade_in_time: VAR, + pub stay_time: VAR, + pub fade_out_time: VAR, + pub xuid: String, + pub platform_online_id: String, +} diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index ed8a5665..a26c6efd 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -36,3 +36,4 @@ pub mod resource_packs_stack_pack; pub mod spawn_biome_type; pub mod spawn_settings; pub mod text_message_data; +pub mod title_type; diff --git a/crates/proto/src/types/title_type.rs b/crates/proto/src/types/title_type.rs new file mode 100644 index 00000000..cdf7ab62 --- /dev/null +++ b/crates/proto/src/types/title_type.rs @@ -0,0 +1,16 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Copy, Clone, Eq, PartialEq)] +#[enum_repr(VAR::)] +pub enum TitleType { + Clear = 0, + Reset = 1, + Title = 2, + Subtitle = 3, + Actionbar = 4, + Times = 5, + TitleTextObject = 6, + SubtitleTextObject = 7, + ActionbarTextObject = 8, +} From b27a74db121ad1486d2e089b009f5abc2e803381 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Thu, 8 Aug 2024 01:13:02 +0800 Subject: [PATCH 17/22] add ToastRequestPacke datapacket --- crates/proto/src/gamepacket.rs | 9 +++++++++ crates/proto/src/login/handle.rs | 1 - crates/proto/src/packets/mod.rs | 1 + crates/proto/src/packets/toast_request_packet.rs | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 crates/proto/src/packets/toast_request_packet.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 96ce0246..19a87b8c 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -32,6 +32,7 @@ use crate::packets::set_local_player_as_initialized::SetLocalPlayerAsInitialized use crate::packets::set_title_packet::SetTitlePacket; use crate::packets::start_game::StartGamePacket; use crate::packets::text_message::TextMessagePacket; +use crate::packets::toast_request_packet::ToastRequestPacket; use bedrockrs_core::int::VAR; use bedrockrs_proto_core::error::ProtoCodecError; use bedrockrs_proto_core::ProtoCodec; @@ -185,6 +186,7 @@ pub enum GamePacket { SubChunkPacket(), SubChunkRequestPacket(), DimensionData(), + ToastRequestPacket(ToastRequestPacket), RequestNetworkSettings(NetworkSettingsRequestPacket), AlexEntityAnimation(), } @@ -336,6 +338,7 @@ impl GamePacket { const SubChunkPacketID: u16 = 174; const SubChunkRequestPacketID: u16 = 175; const DimensionDataID: u16 = 180; + const ccID: u16 = 186; const RequestNetworkSettingsID: u16 = 193; const AlexEntityAnimationID: u16 = 224; } @@ -834,6 +837,9 @@ impl GamePacket { GamePacket::DimensionData() => { unimplemented!() } + GamePacket::ToastRequestPacket(pk) => { + ser_packet!(stream, GamePacket::ToastRequestPackeID, pk) + } GamePacket::RequestNetworkSettings(pk) => { ser_packet!(stream, GamePacket::RequestNetworkSettingsID, pk) } @@ -1295,6 +1301,9 @@ impl GamePacket { GamePacket::DimensionDataID => { unimplemented!() } + GamePacket::ToastRequestPackeID => { + GamePacket::ToastRequestPacket(de_packet!(stream, ToastRequestPacket)) + } GamePacket::RequestNetworkSettingsID => { GamePacket::RequestNetworkSettings(de_packet!(stream, NetworkSettingsRequestPacket)) } diff --git a/crates/proto/src/login/handle.rs b/crates/proto/src/login/handle.rs index f01d84b2..3fd068e4 100644 --- a/crates/proto/src/login/handle.rs +++ b/crates/proto/src/login/handle.rs @@ -8,7 +8,6 @@ use crate::login::play_status::play_status_login; use crate::login::provider::{LoginProviderClient, LoginProviderServer}; use crate::login::start_game::start_game; -use super::add_actor::add_actor; use super::set_title::set_title; pub async fn login_to_server( diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index 4e095167..de15597a 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -27,3 +27,4 @@ pub mod set_local_player_as_initialized; pub mod set_title_packet; pub mod start_game; pub mod text_message; +pub mod toast_request_packet; diff --git a/crates/proto/src/packets/toast_request_packet.rs b/crates/proto/src/packets/toast_request_packet.rs new file mode 100644 index 00000000..49e325d1 --- /dev/null +++ b/crates/proto/src/packets/toast_request_packet.rs @@ -0,0 +1,7 @@ +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct ToastRequestPacket { + pub title: String, + pub content: String, +} From 2a75bde558166feea7f928eef97a2c20dfaa5856 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Thu, 8 Aug 2024 01:14:32 +0800 Subject: [PATCH 18/22] fix ToastRequestPackeID --- 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 19a87b8c..bff232eb 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -338,7 +338,7 @@ impl GamePacket { const SubChunkPacketID: u16 = 174; const SubChunkRequestPacketID: u16 = 175; const DimensionDataID: u16 = 180; - const ccID: u16 = 186; + const ToastRequestPackeID: u16 = 186; const RequestNetworkSettingsID: u16 = 193; const AlexEntityAnimationID: u16 = 224; } From cae083c4f2cdfb886a7b1bb6deccec321a2b49af Mon Sep 17 00:00:00 2001 From: banchen19 Date: Thu, 8 Aug 2024 01:44:46 +0800 Subject: [PATCH 19/22] add CommandRequestPacket --- crates/proto/src/gamepacket.rs | 21 ++++++++++--- .../src/packets/command_request_packet.rs | 12 ++++++++ .../correct_player_move_prediction_packet.rs | 11 +++++++ crates/proto/src/packets/mod.rs | 3 ++ crates/proto/src/types/command_origin_data.rs | 30 +++++++++++++++++++ crates/proto/src/types/mod.rs | 1 + 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 crates/proto/src/packets/command_request_packet.rs create mode 100644 crates/proto/src/packets/correct_player_move_prediction_packet.rs create mode 100644 crates/proto/src/types/command_origin_data.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index bff232eb..355c5ec7 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -7,6 +7,8 @@ use crate::packets::add_actor_packet::AddActorPacket; use crate::packets::animate::AnimatePacket; use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket; use crate::packets::client_cache_status::ClientCacheStatusPacket; +use crate::packets::command_request_packet::CommandRequestPacket; +use crate::packets::correct_player_move_prediction_packet::CorrectPlayerMovePredictionPacket; use crate::packets::disconnect::DisconnectPacket; use crate::packets::emote_list::EmoteListPacket; use crate::packets::handshake_server_to_client::HandshakeServerToClientPacket; @@ -114,7 +116,7 @@ pub enum GamePacket { BossEvent(), ShowCredits(), AvailableCommands(), - CommandRequest(), + CommandRequest(CommandRequestPacket), CommandBlockUpdate(), CommandOutput(), UpdateTrade(), @@ -180,6 +182,7 @@ pub enum GamePacket { UpdatePlayerGameType(), EmoteList(EmoteListPacket), PacketViolationWarning(PacketViolationWarningPacket), + CorrectPlayerMovePredictionPacket(CorrectPlayerMovePredictionPacket), ItemComponent(), FilterTextPacket(), UpdateSubChunkBlocksPacket(), @@ -332,6 +335,7 @@ impl GamePacket { const UpdatePlayerGameTypeID: u16 = 151; const EmoteListID: u16 = 152; const PacketViolationWarningID: u16 = 156; + const CorrectPlayerMovePredictionPacketID: u16 = 161; const ItemComponentID: u16 = 162; const FilterTextPacketID: u16 = 163; const UpdateSubChunkBlocksPacketID: u16 = 172; @@ -621,8 +625,8 @@ impl GamePacket { GamePacket::AvailableCommands() => { unimplemented!() } - GamePacket::CommandRequest() => { - unimplemented!() + GamePacket::CommandRequest(pk) => { + ser_packet!(stream, GamePacket::CommandRequestID, pk) } GamePacket::CommandBlockUpdate() => { unimplemented!() @@ -819,6 +823,9 @@ impl GamePacket { GamePacket::PacketViolationWarning(pk) => { ser_packet!(stream, GamePacket::PacketViolationWarningID, pk) } + GamePacket::CorrectPlayerMovePredictionPacket(pk) => { + ser_packet!(stream, GamePacket::CorrectPlayerMovePredictionPacketID, pk) + } GamePacket::ItemComponent() => { unimplemented!() } @@ -1090,7 +1097,7 @@ impl GamePacket { unimplemented!() } GamePacket::CommandRequestID => { - unimplemented!() + GamePacket::CommandRequest(de_packet!(stream, CommandRequestPacket)) } GamePacket::CommandBlockUpdateID => { unimplemented!() @@ -1283,6 +1290,12 @@ impl GamePacket { GamePacket::PacketViolationWarningID => { GamePacket::PacketViolationWarning(de_packet!(stream, PacketViolationWarningPacket)) } + GamePacket::CorrectPlayerMovePredictionPacketID => { + GamePacket::CorrectPlayerMovePredictionPacket(de_packet!( + stream, + CorrectPlayerMovePredictionPacket + )) + } GamePacket::ItemComponentID => { unimplemented!() } diff --git a/crates/proto/src/packets/command_request_packet.rs b/crates/proto/src/packets/command_request_packet.rs new file mode 100644 index 00000000..849378c3 --- /dev/null +++ b/crates/proto/src/packets/command_request_packet.rs @@ -0,0 +1,12 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; + +use crate::types::command_origin_data::CommandOriginData; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct CommandRequestPacket { + command: String, + command_origin: CommandOriginData, + is_internal_source: bool, + version: VAR, +} diff --git a/crates/proto/src/packets/correct_player_move_prediction_packet.rs b/crates/proto/src/packets/correct_player_move_prediction_packet.rs new file mode 100644 index 00000000..13a06ada --- /dev/null +++ b/crates/proto/src/packets/correct_player_move_prediction_packet.rs @@ -0,0 +1,11 @@ +use bedrockrs_core::{int::LE, Vec3}; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct CorrectPlayerMovePredictionPacket { + pub prediction_type: u8, + pub pos: Vec3>, + pub pos_delta: Vec3>, + pub on_ground: bool, + pub tick: LE, +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index de15597a..f25be0ba 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -1,7 +1,10 @@ +mod Command_Request_Packet; pub mod add_actor_packet; pub mod animate; pub mod chunk_radius_updated; pub mod client_cache_status; +pub mod command_request_packet; +pub mod correct_player_move_prediction_packet; pub mod disconnect; pub mod emote_list; pub mod handshake_server_to_client; diff --git a/crates/proto/src/types/command_origin_data.rs b/crates/proto/src/types/command_origin_data.rs new file mode 100644 index 00000000..777d4ef0 --- /dev/null +++ b/crates/proto/src/types/command_origin_data.rs @@ -0,0 +1,30 @@ +use bedrockrs_core::int::VAR; +use bedrockrs_proto_derive::ProtoCodec; +use uuid::Uuid; +#[derive(ProtoCodec, Debug, Clone)] +#[enum_repr(VAR::)] +pub enum CommandOriginType { + Player = 0, + CommandBlock = 1, + MinecartCommandBlock = 2, + DevConsole = 3, + Test = 4, + AutomationPlayer = 5, + ClientAutomation = 6, + DedicatedServer = 7, + Entity = 8, + Virtual = 9, + GameArgument = 10, + EntityServer = 11, + Precompiled = 12, + GameDirectorEntityServer = 13, + Scripting = 14, + ExecuteContext = 15, +} + +#[derive(ProtoCodec, Debug, Clone)] +pub struct CommandOriginData { + command_type: CommandOriginType, + command_uuid: Uuid, + request_id: String, +} diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index a26c6efd..8912b948 100644 --- a/crates/proto/src/types/mod.rs +++ b/crates/proto/src/types/mod.rs @@ -7,6 +7,7 @@ pub mod base_game_version; pub mod block_action; pub mod chat_restriction_level; pub mod chunk_pos; +pub mod command_origin_data; pub mod connection_request; pub mod dataitem; pub mod disconnect_reason; From 822c9ab1875fdff983b6b7ed86c6c734b9813173 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Thu, 8 Aug 2024 01:45:49 +0800 Subject: [PATCH 20/22] cargo fmt --- crates/proto/src/packets/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index f25be0ba..ae8da073 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -1,4 +1,3 @@ -mod Command_Request_Packet; pub mod add_actor_packet; pub mod animate; pub mod chunk_radius_updated; From 7aebbacaad8025844f3511b62a175ddadff49d53 Mon Sep 17 00:00:00 2001 From: banchen19 Date: Fri, 9 Aug 2024 22:19:39 +0800 Subject: [PATCH 21/22] add ContainerClosePacket --- crates/proto/src/gamepacket.rs | 9 ++-- .../src/packets/container_close_packet.rs | 10 ++++ crates/proto/src/packets/mod.rs | 1 + crates/proto/src/types/command_origin_data.rs | 6 +-- crates/proto/src/types/container_type.rs | 46 +++++++++++++++++++ crates/proto/src/types/mod.rs | 1 + 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 crates/proto/src/packets/container_close_packet.rs create mode 100644 crates/proto/src/types/container_type.rs diff --git a/crates/proto/src/gamepacket.rs b/crates/proto/src/gamepacket.rs index 355c5ec7..d77590fe 100644 --- a/crates/proto/src/gamepacket.rs +++ b/crates/proto/src/gamepacket.rs @@ -8,6 +8,7 @@ use crate::packets::animate::AnimatePacket; 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::correct_player_move_prediction_packet::CorrectPlayerMovePredictionPacket; use crate::packets::disconnect::DisconnectPacket; use crate::packets::emote_list::EmoteListPacket; @@ -86,7 +87,7 @@ pub enum GamePacket { Animate(AnimatePacket), Respawn(), ContainerOpen(), - ContainerClose(), + ContainerClose(ContainerClosePacket), PlayerHotbar(), InventoryContent(), InventorySlot(), @@ -535,8 +536,8 @@ impl GamePacket { GamePacket::ContainerOpen() => { unimplemented!() } - GamePacket::ContainerClose() => { - unimplemented!() + GamePacket::ContainerClose(pk) => { + ser_packet!(stream, GamePacket::ContainerCloseID, pk) } GamePacket::PlayerHotbar() => { unimplemented!() @@ -1007,7 +1008,7 @@ impl GamePacket { unimplemented!() } GamePacket::ContainerCloseID => { - unimplemented!() + GamePacket::ContainerClose(de_packet!(stream, ContainerClosePacket)) } GamePacket::PlayerHotbarID => { unimplemented!() diff --git a/crates/proto/src/packets/container_close_packet.rs b/crates/proto/src/packets/container_close_packet.rs new file mode 100644 index 00000000..b2e37382 --- /dev/null +++ b/crates/proto/src/packets/container_close_packet.rs @@ -0,0 +1,10 @@ +use bedrockrs_proto_derive::ProtoCodec; + +use crate::types::container_type::ContainerType; + +#[derive(ProtoCodec, Debug, Clone)] +pub struct ContainerClosePacket { + container_id: u8, + container_type: ContainerType, + server_initiated_close: bool, +} diff --git a/crates/proto/src/packets/mod.rs b/crates/proto/src/packets/mod.rs index ae8da073..cd8321ab 100644 --- a/crates/proto/src/packets/mod.rs +++ b/crates/proto/src/packets/mod.rs @@ -3,6 +3,7 @@ pub mod animate; pub mod chunk_radius_updated; pub mod client_cache_status; pub mod command_request_packet; +pub mod container_close_packet; pub mod correct_player_move_prediction_packet; pub mod disconnect; pub mod emote_list; diff --git a/crates/proto/src/types/command_origin_data.rs b/crates/proto/src/types/command_origin_data.rs index 777d4ef0..8edc29bd 100644 --- a/crates/proto/src/types/command_origin_data.rs +++ b/crates/proto/src/types/command_origin_data.rs @@ -24,7 +24,7 @@ pub enum CommandOriginType { #[derive(ProtoCodec, Debug, Clone)] pub struct CommandOriginData { - command_type: CommandOriginType, - command_uuid: Uuid, - request_id: String, + pub command_type: CommandOriginType, + pub command_uuid: Uuid, + pub request_id: String, } diff --git a/crates/proto/src/types/container_type.rs b/crates/proto/src/types/container_type.rs new file mode 100644 index 00000000..21582a8c --- /dev/null +++ b/crates/proto/src/types/container_type.rs @@ -0,0 +1,46 @@ +use bedrockrs_core::int::BE; +use bedrockrs_proto_derive::ProtoCodec; + +#[derive(ProtoCodec, Debug, Copy, Clone, Eq, PartialEq)] +#[enum_repr(BE::)] +pub enum ContainerType { + NONE = -9, + INVENTORY = -1, + CONTAINER = 0, + WORKBENCH = 1, + FURNACE = 2, + ENCHANTMENT = 3, + BREWING_STAND = 4, + ANVIL = 5, + DISPENSER = 6, + DROPPER = 7, + HOPPER = 8, + CAULDRON = 9, + MINECART_CHEST = 10, + MINECART_HOPPER = 11, + HORSE = 12, + BEACON = 13, + STRUCTURE_EDITOR = 14, + TRADE = 15, + COMMAND_BLOCK = 16, + JUKEBOX = 17, + ARMOR = 18, + HAND = 19, + COMPOUND_CREATOR = 20, + ELEMENT_CONSTRUCTOR = 21, + MATERIAL_REDUCER = 22, + LAB_TABLE = 23, + LOOM = 24, + LECTERN = 25, + GRINDSTONE = 26, + BLAST_FURNACE = 27, + SMOKER = 28, + STONECUTTER = 29, + CARTOGRAPHY = 30, + HUD = 31, + JIGSAW_EDITOR = 32, + SMITHING_TABLE = 33, + CHEST_BOAT = 34, + DECORATED_POT = 35, + CRAFTER = 36, +} diff --git a/crates/proto/src/types/mod.rs b/crates/proto/src/types/mod.rs index 8912b948..7d605ed8 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_type; pub mod dataitem; pub mod disconnect_reason; pub mod edu_shared_uri_resource; From bf50de0fac1a8fb7915e87bfe22eb9382d0eca59 Mon Sep 17 00:00:00 2001 From: Lucy Date: Fri, 9 Aug 2024 16:27:57 +0200 Subject: [PATCH 22/22] Update handle.rs --- crates/proto/src/login/handle.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/proto/src/login/handle.rs b/crates/proto/src/login/handle.rs index 3fd068e4..b1bb1d5f 100644 --- a/crates/proto/src/login/handle.rs +++ b/crates/proto/src/login/handle.rs @@ -24,7 +24,6 @@ pub async fn login_to_server( packs(conn, &mut provider).await?; start_game(conn, &mut provider).await?; - set_title(conn, &mut provider).await?; Ok(()) }