From ffdc85078560d159f303935c1c6cf97636e2a788 Mon Sep 17 00:00:00 2001 From: Adrian Date: Thu, 4 Jul 2024 16:59:25 +0200 Subject: [PATCH] rust fmt --- bedrock_core/src/actor_runtime_id.rs | 2 - bedrock_core/src/actor_unique_id.rs | 2 - bedrock_core/src/generator_type.rs | 2 +- bedrock_core/src/lib.rs | 16 ++-- bedrock_core/src/semver.rs | 8 +- packs/src/behavior/behavior_pack.rs | 88 +++++++++++++-------- packs/src/language/mod.rs | 12 +-- packs/src/language/values.rs | 25 +++--- packs/src/lib.rs | 2 +- packs/src/pack.rs | 3 +- packs/src/resource/resource_pack.rs | 10 +-- proto/src/connection.rs | 2 - proto/src/gamepacket.rs | 8 +- proto/src/login/handle.rs | 2 +- proto/src/login/mod.rs | 2 +- proto/src/login/start_game.rs | 25 ++++-- proto/src/packets/resource_packs_stack.rs | 7 +- proto/src/packets/start_game.rs | 7 +- proto/src/types/chat_restriction_level.rs | 15 ++-- proto/src/types/editor_world_type.rs | 13 +-- proto/src/types/edu_shared_uri_resource.rs | 4 +- proto/src/types/game_rule.rs | 2 +- proto/src/types/level_settings.rs | 5 +- proto/src/types/mod.rs | 16 ++-- proto/src/types/network_block_pos.rs | 2 +- proto/src/types/player_movement_mode.rs | 15 ++-- proto/src/types/player_movement_settings.rs | 3 +- proto/src/types/spawn_biome_type.rs | 11 +-- proto/src/types/spawn_settings.rs | 2 +- proto_core/src/types/actor_runtime_id.rs | 6 +- proto_core/src/types/actor_unique_id.rs | 5 +- proto_core/src/types/difficulty.rs | 19 ++--- proto_core/src/types/dimension.rs | 16 ++-- proto_core/src/types/gamemode.rs | 24 +++--- proto_core/src/types/generator_type.rs | 22 +++--- proto_core/src/types/mod.rs | 16 ++-- proto_core/src/types/nbt_tag.rs | 13 +-- proto_core/src/types/uuid.rs | 5 +- proto_core/src/types/vec.rs | 5 +- 39 files changed, 251 insertions(+), 191 deletions(-) diff --git a/bedrock_core/src/actor_runtime_id.rs b/bedrock_core/src/actor_runtime_id.rs index b4335b2d..b91a7ff5 100644 --- a/bedrock_core/src/actor_runtime_id.rs +++ b/bedrock_core/src/actor_runtime_id.rs @@ -1,4 +1,2 @@ -use crate::VAR; - #[derive(Debug, Clone)] pub struct ActorRuntimeID(pub u64); diff --git a/bedrock_core/src/actor_unique_id.rs b/bedrock_core/src/actor_unique_id.rs index 38b7a5e2..eae9b1ad 100644 --- a/bedrock_core/src/actor_unique_id.rs +++ b/bedrock_core/src/actor_unique_id.rs @@ -1,4 +1,2 @@ -use crate::VAR; - #[derive(Debug, Clone)] pub struct ActorUniqueID(pub i64); diff --git a/bedrock_core/src/generator_type.rs b/bedrock_core/src/generator_type.rs index 629ca40d..1540bffb 100644 --- a/bedrock_core/src/generator_type.rs +++ b/bedrock_core/src/generator_type.rs @@ -6,4 +6,4 @@ pub enum GeneratorType { Nether, End, Void, -} \ No newline at end of file +} diff --git a/bedrock_core/src/lib.rs b/bedrock_core/src/lib.rs index 8a0255cc..95e065fd 100644 --- a/bedrock_core/src/lib.rs +++ b/bedrock_core/src/lib.rs @@ -1,30 +1,30 @@ +pub use actor_runtime_id::*; +pub use actor_unique_id::*; pub use difficulty::*; pub use dimension::*; +pub use generator_type::*; pub use int::be::*; pub use int::le::*; pub use int::var::*; pub use permissions_level::*; +pub use semver::*; pub use stream::*; pub use uuid::*; pub use vec::vec2::Vec2; pub use vec::vec2f::Vec2f; pub use vec::vec3::Vec3; pub use vec::vec3f::Vec3f; -pub use semver::*; -pub use actor_unique_id::*; -pub use actor_runtime_id::*; -pub use generator_type::*; pub mod int; pub mod vec; pub mod stream; +pub mod actor_runtime_id; +pub mod actor_unique_id; pub mod difficulty; pub mod dimension; -pub mod permissions_level; -pub mod actor_unique_id; -pub mod actor_runtime_id; -pub mod generator_type; pub mod gamemode; +pub mod generator_type; +pub mod permissions_level; pub mod semver; diff --git a/bedrock_core/src/semver.rs b/bedrock_core/src/semver.rs index 3434a819..7790f414 100644 --- a/bedrock_core/src/semver.rs +++ b/bedrock_core/src/semver.rs @@ -10,7 +10,11 @@ pub struct SemVer { impl Debug for SemVer { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}.{}.{}.{}", self.major, self.minor, self.patch, self.build) + write!( + f, + "{}.{}.{}.{}", + self.major, self.minor, self.patch, self.build + ) } } @@ -18,4 +22,4 @@ impl Display for SemVer { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}.{}.{}", self.major, self.minor, self.patch) } -} \ No newline at end of file +} diff --git a/packs/src/behavior/behavior_pack.rs b/packs/src/behavior/behavior_pack.rs index 8ddd751b..eb8eeaf4 100644 --- a/packs/src/behavior/behavior_pack.rs +++ b/packs/src/behavior/behavior_pack.rs @@ -1,13 +1,12 @@ -use std::collections::HashMap; use std::path::{Path, PathBuf}; -use std::string::FromUtf8Error; + use bedrock_core::SemVer; -use image::{ImageBuffer, RgbaImage}; -use serde_json::{Number, Value}; -use uuid::{Uuid, Version}; +use image::RgbaImage; +use serde_json::Value; +use uuid::Uuid; use crate::error::PackError; -use crate::language::{LanguageValues, Languages}; +use crate::language::Languages; use crate::pack::Pack; #[derive(Debug, Clone)] @@ -38,53 +37,78 @@ impl Pack for BehaviorPack { fn import(path: impl AsRef) -> Result where - Self: Sized + Self: Sized, { // Convert the given path into a PathBuf let directory: PathBuf = path.as_ref().to_path_buf(); - let manifest_content = std::fs::read(directory.join("manifest.json")).map_err(|e| { todo!() })?; + let manifest_content = + std::fs::read(directory.join("manifest.json")).map_err(|e| todo!())?; - let text = String::from_utf8(manifest_content).map_err(|e| { todo!() })?; + let text = String::from_utf8(manifest_content).map_err(|e| todo!())?; let json: Value = match serde_json::from_str(&text) { - Ok(v) => { v } - Err(e) => { todo!() } + Ok(v) => v, + Err(e) => { + todo!() + } }; let main_obj = match json { - Value::Object(ref v) => { v.clone() } - other => { todo!() } + Value::Object(ref v) => v.clone(), + other => { + todo!() + } }; let format_version: u32 = match main_obj.get("format_version") { - Some(Value::Number(ref v)) => { match v.as_u64() { - None => { todo!() } - Some(v) => { match v.try_into() { - Ok(v) => { v } - Err(e) => { todo!() } - }} - }} - Some(other) => { todo!() } - None => { todo!() } + Some(Value::Number(ref v)) => match v.as_u64() { + None => { + todo!() + } + Some(v) => match v.try_into() { + Ok(v) => v, + Err(e) => { + todo!() + } + }, + }, + Some(other) => { + todo!() + } + None => { + todo!() + } }; let header_obj = match main_obj.get("header") { - Some(Value::Object(ref v)) => { v.clone() } - Some(other) => { todo!() } - None => { todo!() } + Some(Value::Object(ref v)) => v.clone(), + Some(other) => { + todo!() + } + None => { + todo!() + } }; let name = match header_obj.get("name") { - Some(Value::String(v)) => { v.clone() } - Some(other) => { todo!() } - None => { todo!() } + Some(Value::String(v)) => v.clone(), + Some(other) => { + todo!() + } + None => { + todo!() + } }; let description = match header_obj.get("description") { - Some(Value::String(v)) => { v.clone() } - Some(other) => { todo!() } - None => { todo!() } + Some(Value::String(v)) => v.clone(), + Some(other) => { + todo!() + } + None => { + todo!() + } }; println!("\"format_version\": {format_version:?}"); @@ -98,7 +122,7 @@ impl Pack for BehaviorPack { fn export(path: impl AsRef) -> Result where - Self: Sized + Self: Sized, { todo!() } diff --git a/packs/src/language/mod.rs b/packs/src/language/mod.rs index 35b7d14d..8141257b 100644 --- a/packs/src/language/mod.rs +++ b/packs/src/language/mod.rs @@ -1,10 +1,12 @@ -pub mod values; - use std::collections::HashMap; use std::path::Path; + pub use values::*; + use crate::error::PackError; +pub mod values; + #[derive(Debug, Clone)] pub struct Languages(HashMap); @@ -14,8 +16,6 @@ impl Languages { } pub fn languages(&self) -> Vec { - self.0.keys().map(|f| { - f.clone() - }).collect() + self.0.keys().map(|f| f.clone()).collect() } -} \ No newline at end of file +} diff --git a/packs/src/language/values.rs b/packs/src/language/values.rs index 9cb315ec..31101b94 100644 --- a/packs/src/language/values.rs +++ b/packs/src/language/values.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::path::Path; + use crate::error::PackError; #[derive(Debug, Clone)] @@ -8,13 +9,17 @@ pub struct LanguageValues(HashMap); impl LanguageValues { pub fn open(path: impl AsRef) -> Result { let data = match std::fs::read(path) { - Ok(v) => { v } - Err(e) => { todo!() } + Ok(v) => v, + Err(e) => { + todo!() + } }; let lines = match String::from_utf8(data) { - Ok(v) => { v } - Err(e) => { todo!() } + Ok(v) => v, + Err(e) => { + todo!() + } }; let mut map = HashMap::new(); @@ -34,18 +39,20 @@ impl LanguageValues { // Remove possible inline comments let line = match line.split_once("\t##") { - None => { line } - Some((v, _)) => { v } + None => line, + Some((v, _)) => v, }; // Split identifier and value let (id, val) = match line.split_once("=") { - None => { todo!() } - Some((i, v)) => { (String::from(i), String::from(v)) } + None => { + todo!() + } + Some((i, v)) => (String::from(i), String::from(v)), }; map.insert(id, val); - }; + } Ok(Self(map)) } diff --git a/packs/src/lib.rs b/packs/src/lib.rs index 04554e52..42a2cb3f 100644 --- a/packs/src/lib.rs +++ b/packs/src/lib.rs @@ -1,5 +1,5 @@ pub mod behavior; pub mod error; +pub mod language; pub mod pack; pub mod resource; -pub mod language; diff --git a/packs/src/pack.rs b/packs/src/pack.rs index bcd4c80f..92d4ed59 100644 --- a/packs/src/pack.rs +++ b/packs/src/pack.rs @@ -1,6 +1,7 @@ use std::path::Path; + use bedrock_core::SemVer; -use uuid::{Uuid, Version}; +use uuid::Uuid; use crate::error::PackError; diff --git a/packs/src/resource/resource_pack.rs b/packs/src/resource/resource_pack.rs index d2edc6e8..a3ba660c 100644 --- a/packs/src/resource/resource_pack.rs +++ b/packs/src/resource/resource_pack.rs @@ -1,11 +1,11 @@ -use std::collections::HashMap; use std::path::Path; + use bedrock_core::SemVer; use image::RgbaImage; -use uuid::{Uuid, Version}; +use uuid::Uuid; use crate::error::PackError; -use crate::language::{LanguageValues, Languages}; +use crate::language::Languages; use crate::pack::Pack; #[derive(Debug, Clone)] @@ -36,14 +36,14 @@ impl Pack for ResourcePack { fn import(path: impl AsRef) -> Result where - Self: Sized + Self: Sized, { todo!() } fn export(path: impl AsRef) -> Result where - Self: Sized + Self: Sized, { todo!() } diff --git a/proto/src/connection.rs b/proto/src/connection.rs index d112575f..3ab47d06 100644 --- a/proto/src/connection.rs +++ b/proto/src/connection.rs @@ -38,8 +38,6 @@ impl Connection { } } - - pub async fn send(&mut self, gamepackets: Vec) -> Result<(), ConnectionError> { let mut pk_stream = ByteStreamWrite::new(); diff --git a/proto/src/gamepacket.rs b/proto/src/gamepacket.rs index ddca14c3..d92b737c 100644 --- a/proto/src/gamepacket.rs +++ b/proto/src/gamepacket.rs @@ -328,6 +328,8 @@ macro_rules! ser_packet { ($stream:expr, $packet_id:expr, $packet_data:expr) => {{ let mut pk_stream = ByteStreamWrite::new(); + println!("[SEND] {:#?}", $packet_data); + // TODO add correct header generation // let header = ""; @@ -887,9 +889,7 @@ impl GamePacket { GamePacket::SetTimeID => { unimplemented!() } - GamePacket::StartGameID => GamePacket::StartGame( - de_packet!(stream, StartGamePacket), - ), + GamePacket::StartGameID => GamePacket::StartGame(de_packet!(stream, StartGamePacket)), GamePacket::AddPlayerID => { unimplemented!() } @@ -1303,6 +1303,8 @@ impl GamePacket { } }; + println!("[RECV] {:#?}", game_packet); + Ok((game_packet, sub_client_sender_id, sub_client_target_id)) } } diff --git a/proto/src/login/handle.rs b/proto/src/login/handle.rs index 7b7aedee..b70ada5a 100644 --- a/proto/src/login/handle.rs +++ b/proto/src/login/handle.rs @@ -4,8 +4,8 @@ use crate::login::handshake::handshake; use crate::login::login::login; use crate::login::network_settings::network_settings; use crate::login::packs::packs; -use crate::login::provider::{LoginProviderClient, LoginProviderServer}; use crate::login::play_status::play_status_login; +use crate::login::provider::{LoginProviderClient, LoginProviderServer}; use crate::login::start_game::start_game; pub async fn login_to_server( diff --git a/proto/src/login/mod.rs b/proto/src/login/mod.rs index e41474f7..6bccfb49 100644 --- a/proto/src/login/mod.rs +++ b/proto/src/login/mod.rs @@ -5,6 +5,6 @@ mod handshake; mod login; mod network_settings; mod packs; +mod play_status; pub mod provider; mod start_game; -mod play_status; diff --git a/proto/src/login/start_game.rs b/proto/src/login/start_game.rs index d1414dfa..eb03f34a 100644 --- a/proto/src/login/start_game.rs +++ b/proto/src/login/start_game.rs @@ -1,10 +1,13 @@ -use bedrock_core::{ActorRuntimeID, ActorUniqueID, Difficulty, Dimension, GeneratorType, LE, Uuid, VAR, Vec2, Vec3}; use bedrock_core::gamemode::Gamemode; +use bedrock_core::{ + ActorRuntimeID, ActorUniqueID, Difficulty, Dimension, GeneratorType, Uuid, Vec2, Vec3, LE, VAR, +}; use nbt::NbtTag; + use crate::connection::ConnectionShard; use crate::error::LoginError; use crate::gamepacket::GamePacket; -use crate::login::provider::{LoginProviderServer, LoginProviderStatus}; +use crate::login::provider::LoginProviderServer; use crate::packets::start_game::StartGamePacket; use crate::types::base_game_version::BaseGameVersion; use crate::types::chat_restriction_level::ChatRestrictionLevel; @@ -19,13 +22,15 @@ use crate::types::player_movement_settings::PlayerMovementSettings; use crate::types::spawn_biome_type::SpawnBiomeType; use crate::types::spawn_settings::SpawnSettings; -pub async fn start_game(conn: &mut ConnectionShard, provider: &mut impl LoginProviderServer, +pub async fn start_game( + conn: &mut ConnectionShard, + provider: &mut impl LoginProviderServer, ) -> Result<(), LoginError> { ////////////////////////////////////// // Start Game Packet ////////////////////////////////////// - let start_game = StartGamePacket{ + let start_game = StartGamePacket { target_actor_id: ActorUniqueID(1), target_runtime_id: ActorRuntimeID(1), actor_game_type: Gamemode::Survival, @@ -45,7 +50,7 @@ pub async fn start_game(conn: &mut ConnectionShard, provider: &mut impl LoginPro default_spawn_block: NetworkBlockPos { x: VAR::new(0), y: VAR::new(0), - z: VAR::new(0) + z: VAR::new(0), }, achievements_disabled: false, editor_world_type: EditorWorldType::NotEditor, @@ -65,7 +70,10 @@ pub async fn start_game(conn: &mut ConnectionShard, provider: &mut impl LoginPro commands_enabled: false, texture_pack_required: false, rules: vec![], - experiments: Experiments { experiments: vec![], ever_toggled: false }, + experiments: Experiments { + experiments: vec![], + ever_toggled: false, + }, bonus_chest: false, start_with_map: false, player_permission: VAR::new(0), @@ -84,7 +92,10 @@ pub async fn start_game(conn: &mut ConnectionShard, provider: &mut impl LoginPro limited_world_width: LE::new(0), limited_world_depth: LE::new(0), new_nether: true, - edu_shared_uri_resource: EduSharedResourceUri { button_name: String::from(""), link_uri: String::from("") }, + edu_shared_uri_resource: EduSharedResourceUri { + button_name: String::from(""), + link_uri: String::from(""), + }, force_experimental_gameplay: Some(false), chat_restriction_level: ChatRestrictionLevel::None, disable_player_interactions: false, diff --git a/proto/src/packets/resource_packs_stack.rs b/proto/src/packets/resource_packs_stack.rs index 88b6ee3f..0db0753c 100644 --- a/proto/src/packets/resource_packs_stack.rs +++ b/proto/src/packets/resource_packs_stack.rs @@ -1,5 +1,6 @@ -use proto_derive::ProtoCodec; use bedrock_core::VAR; +use proto_derive::ProtoCodec; + use crate::types::base_game_version::BaseGameVersion; use crate::types::experiments::Experiments; use crate::types::resource_packs_stack_pack::ResourcePacksStackPack; @@ -7,9 +8,9 @@ use crate::types::resource_packs_stack_pack::ResourcePacksStackPack; #[derive(Debug, Clone, ProtoCodec)] pub struct ResourcePacksStackPacket { pub texture_pack_required: bool, - #[len_type(VAR::)] + #[len_type(VAR::< i32 >)] pub addons: Vec, - #[len_type(VAR::)] + #[len_type(VAR::< i32 >)] pub texture_packs: Vec, pub base_game_version: BaseGameVersion, pub experiments: Experiments, diff --git a/proto/src/packets/start_game.rs b/proto/src/packets/start_game.rs index 44c07ada..6880d02d 100644 --- a/proto/src/packets/start_game.rs +++ b/proto/src/packets/start_game.rs @@ -1,7 +1,8 @@ -use bedrock_core::{ActorRuntimeID, ActorUniqueID, LE, Uuid, VAR, Vec2, Vec3}; use bedrock_core::gamemode::Gamemode; +use bedrock_core::{ActorRuntimeID, ActorUniqueID, Uuid, Vec2, Vec3, LE, VAR}; use nbt::NbtTag; use proto_derive::ProtoCodec; + use crate::types::level_settings::LevelSettings; use crate::types::network_permissions::NetworkPermissions; use crate::types::player_movement_settings::PlayerMovementSettings; @@ -22,10 +23,10 @@ pub struct StartGamePacket { pub current_level_time: LE, pub enchantment_seed: VAR, // TODO Add real value - #[len_type(VAR::)] + #[len_type(VAR::< u32 >)] pub block_properties: Vec, // TODO Add real value - #[len_type(VAR::)] + #[len_type(VAR::< u32 >)] pub items: Vec, pub multiplayer_correlation_id: String, pub enable_item_stack_net_manager: bool, diff --git a/proto/src/types/chat_restriction_level.rs b/proto/src/types/chat_restriction_level.rs index 55250ad4..2b2b7e6b 100644 --- a/proto/src/types/chat_restriction_level.rs +++ b/proto/src/types/chat_restriction_level.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use bedrock_core::LE; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::LE; use proto_core::error::ProtoCodecError; use proto_core::ProtoCodec; @@ -15,18 +16,18 @@ pub enum ChatRestrictionLevel { impl ProtoCodec for ChatRestrictionLevel { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - ChatRestrictionLevel::None => { 0x00 } - ChatRestrictionLevel::Dropped => { 0x01 } - ChatRestrictionLevel::Disabled => { 0x02 } + ChatRestrictionLevel::None => 0x00, + ChatRestrictionLevel::Dropped => 0x01, + ChatRestrictionLevel::Disabled => 0x02, }; match LE::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto/src/types/editor_world_type.rs b/proto/src/types/editor_world_type.rs index ffcd4493..ee82c013 100644 --- a/proto/src/types/editor_world_type.rs +++ b/proto/src/types/editor_world_type.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use bedrock_core::{LE, VAR}; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::VAR; use proto_core::error::ProtoCodecError; use proto_core::ProtoCodec; @@ -15,14 +16,14 @@ pub enum EditorWorldType { impl ProtoCodec for EditorWorldType { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - EditorWorldType::NotEditor => { 0x00 } - EditorWorldType::Project => { 0x01 } - EditorWorldType::TestLevel => { 0x02 } + EditorWorldType::NotEditor => 0x00, + EditorWorldType::Project => 0x01, + EditorWorldType::TestLevel => 0x02, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } diff --git a/proto/src/types/edu_shared_uri_resource.rs b/proto/src/types/edu_shared_uri_resource.rs index 5b9a5698..08d0d7f7 100644 --- a/proto/src/types/edu_shared_uri_resource.rs +++ b/proto/src/types/edu_shared_uri_resource.rs @@ -3,5 +3,5 @@ use proto_derive::ProtoCodec; #[derive(ProtoCodec, Debug, Clone)] pub struct EduSharedResourceUri { pub button_name: String, - pub link_uri: String -} \ No newline at end of file + pub link_uri: String, +} diff --git a/proto/src/types/game_rule.rs b/proto/src/types/game_rule.rs index 6a6d8903..981344a8 100644 --- a/proto/src/types/game_rule.rs +++ b/proto/src/types/game_rule.rs @@ -5,5 +5,5 @@ pub struct GameRule { name: String, editable: bool, // TODO figure out what the value can be, the proto docs are fucked up and say that it is 3 varints - value: u8 + value: u8, } diff --git a/proto/src/types/level_settings.rs b/proto/src/types/level_settings.rs index ad5a5c43..9307d0d7 100644 --- a/proto/src/types/level_settings.rs +++ b/proto/src/types/level_settings.rs @@ -1,6 +1,7 @@ -use bedrock_core::{Difficulty, GeneratorType, LE, VAR, Vec3}; use bedrock_core::gamemode::Gamemode; +use bedrock_core::{Difficulty, GeneratorType, LE, VAR}; use proto_derive::ProtoCodec; + use crate::types::base_game_version::BaseGameVersion; use crate::types::chat_restriction_level::ChatRestrictionLevel; use crate::types::editor_world_type::EditorWorldType; @@ -36,7 +37,7 @@ pub struct LevelSettings { pub broadcasting_settings_platform: VAR, pub commands_enabled: bool, pub texture_pack_required: bool, - #[len_type(VAR::)] + #[len_type(VAR::< u32 >)] pub rules: Vec, pub experiments: Experiments, pub bonus_chest: bool, diff --git a/proto/src/types/mod.rs b/proto/src/types/mod.rs index bd15b3ee..97d2583d 100644 --- a/proto/src/types/mod.rs +++ b/proto/src/types/mod.rs @@ -1,21 +1,21 @@ pub mod base_game_version; +pub mod chat_restriction_level; pub mod connection_request; +pub mod editor_world_type; +pub mod edu_shared_uri_resource; pub mod experiment; pub mod experiments; +pub mod game_rule; pub mod level_settings; +pub mod network_block_pos; +pub mod network_permissions; pub mod pack_info_behavior; pub mod pack_info_resource; pub mod pack_url; pub mod play_status; +pub mod player_movement_mode; pub mod player_movement_settings; pub mod resource_packs_response_status; pub mod resource_packs_stack_pack; -pub mod network_permissions; -pub mod spawn_settings; -pub mod game_rule; -pub mod edu_shared_uri_resource; -pub mod chat_restriction_level; -pub mod editor_world_type; pub mod spawn_biome_type; -pub mod player_movement_mode; -pub mod network_block_pos; \ No newline at end of file +pub mod spawn_settings; diff --git a/proto/src/types/network_block_pos.rs b/proto/src/types/network_block_pos.rs index 2cb8a542..da429e72 100644 --- a/proto/src/types/network_block_pos.rs +++ b/proto/src/types/network_block_pos.rs @@ -6,4 +6,4 @@ pub struct NetworkBlockPos { pub x: VAR, pub y: VAR, pub z: VAR, -} \ No newline at end of file +} diff --git a/proto/src/types/player_movement_mode.rs b/proto/src/types/player_movement_mode.rs index 437fe26c..8bfa75d5 100644 --- a/proto/src/types/player_movement_mode.rs +++ b/proto/src/types/player_movement_mode.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use bedrock_core::{LE, VAR}; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::VAR; use proto_core::error::ProtoCodecError; use proto_core::ProtoCodec; @@ -15,18 +16,18 @@ pub enum PlayerMovementMode { impl ProtoCodec for PlayerMovementMode { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - PlayerMovementMode::Client => { 0x00 } - PlayerMovementMode::Server => { 0x01 } - PlayerMovementMode::ServerWithRewind => { 0x02 } + PlayerMovementMode::Client => 0x00, + PlayerMovementMode::Server => 0x01, + PlayerMovementMode::ServerWithRewind => 0x02, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto/src/types/player_movement_settings.rs b/proto/src/types/player_movement_settings.rs index c14a36a3..5b684561 100644 --- a/proto/src/types/player_movement_settings.rs +++ b/proto/src/types/player_movement_settings.rs @@ -1,10 +1,11 @@ use bedrock_core::VAR; use proto_derive::ProtoCodec; + use crate::types::player_movement_mode::PlayerMovementMode; #[derive(ProtoCodec, Debug, Clone)] pub struct PlayerMovementSettings { pub authority_mode: PlayerMovementMode, pub rewind_history_size: VAR, - pub server_authoritative_block_breaking: bool + pub server_authoritative_block_breaking: bool, } diff --git a/proto/src/types/spawn_biome_type.rs b/proto/src/types/spawn_biome_type.rs index 31815ace..5125c1cc 100644 --- a/proto/src/types/spawn_biome_type.rs +++ b/proto/src/types/spawn_biome_type.rs @@ -1,7 +1,8 @@ use std::sync::Arc; -use bedrock_core::LE; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::LE; use proto_core::error::ProtoCodecError; use proto_core::ProtoCodec; @@ -14,13 +15,13 @@ pub enum SpawnBiomeType { impl ProtoCodec for SpawnBiomeType { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - SpawnBiomeType::Default => { 0x00 } - SpawnBiomeType::UserDefined => { 0x01 } + SpawnBiomeType::Default => 0x00, + SpawnBiomeType::UserDefined => 0x01, }; match LE::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } diff --git a/proto/src/types/spawn_settings.rs b/proto/src/types/spawn_settings.rs index d10b00a8..e33bd6c8 100644 --- a/proto/src/types/spawn_settings.rs +++ b/proto/src/types/spawn_settings.rs @@ -8,4 +8,4 @@ pub struct SpawnSettings { pub biome_type: SpawnBiomeType, pub user_defined_biome_name: String, pub dimension: Dimension, -} \ No newline at end of file +} diff --git a/proto_core/src/types/actor_runtime_id.rs b/proto_core/src/types/actor_runtime_id.rs index 75cff4f5..9dcbf561 100644 --- a/proto_core/src/types/actor_runtime_id.rs +++ b/proto_core/src/types/actor_runtime_id.rs @@ -1,8 +1,8 @@ -use bedrock_core::{ActorRuntimeID, VAR}; -use bedrock_core::read::ByteStreamRead; -use bedrock_core::write::ByteStreamWrite; use crate::error::ProtoCodecError; use crate::ProtoCodec; +use bedrock_core::read::ByteStreamRead; +use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{ActorRuntimeID, VAR}; impl ProtoCodec for ActorRuntimeID { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { diff --git a/proto_core/src/types/actor_unique_id.rs b/proto_core/src/types/actor_unique_id.rs index 71931d30..0ad3370d 100644 --- a/proto_core/src/types/actor_unique_id.rs +++ b/proto_core/src/types/actor_unique_id.rs @@ -1,6 +1,7 @@ -use bedrock_core::{ActorRuntimeID, ActorUniqueID, VAR}; use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{ActorUniqueID, VAR}; + use crate::error::ProtoCodecError; use crate::ProtoCodec; @@ -12,4 +13,4 @@ impl ProtoCodec for ActorUniqueID { fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { Ok(Self(VAR::proto_deserialize(stream)?.into_inner())) } -} \ No newline at end of file +} diff --git a/proto_core/src/types/difficulty.rs b/proto_core/src/types/difficulty.rs index 48db3941..9753f33f 100644 --- a/proto_core/src/types/difficulty.rs +++ b/proto_core/src/types/difficulty.rs @@ -1,27 +1,28 @@ use std::sync::Arc; -use bedrock_core::{Difficulty, LE, VAR}; -use bedrock_core::gamemode::Gamemode; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{Difficulty, VAR}; + use crate::error::ProtoCodecError; use crate::ProtoCodec; impl ProtoCodec for Difficulty { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - Difficulty::Peaceful => { 0x00 } - Difficulty::Easy => { 0x01 } - Difficulty::Normal => { 0x02 } - Difficulty::Hard => { 0x03 } + Difficulty::Peaceful => 0x00, + Difficulty::Easy => 0x01, + Difficulty::Normal => 0x02, + Difficulty::Hard => 0x03, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto_core/src/types/dimension.rs b/proto_core/src/types/dimension.rs index 796bb525..241b83a3 100644 --- a/proto_core/src/types/dimension.rs +++ b/proto_core/src/types/dimension.rs @@ -1,25 +1,27 @@ use std::sync::Arc; -use bedrock_core::{Dimension, LE, VAR}; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{Dimension, VAR}; + use crate::error::ProtoCodecError; use crate::ProtoCodec; impl ProtoCodec for Dimension { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - Dimension::Overworld => { 0x00 } - Dimension::Nether => { 0x01 } - Dimension::End => { 0x02 } + Dimension::Overworld => 0x00, + Dimension::Nether => 0x01, + Dimension::End => 0x02, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto_core/src/types/gamemode.rs b/proto_core/src/types/gamemode.rs index 8bf55fee..00a5a169 100644 --- a/proto_core/src/types/gamemode.rs +++ b/proto_core/src/types/gamemode.rs @@ -1,30 +1,32 @@ use std::sync::Arc; + use bedrock_core::gamemode::Gamemode; -use bedrock_core::{LE, VAR}; use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::VAR; + use crate::error::ProtoCodecError; use crate::ProtoCodec; impl ProtoCodec for Gamemode { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - Gamemode::Survival => { 0x00 } - Gamemode::Creative => { 0x01 } - Gamemode::Adventure => { 0x02 } - Gamemode::SurvivalSpectator => { 0x03 } - Gamemode::CreativeSpectator => { 0x04 } - Gamemode::Default => { 0x05 } - Gamemode::Spectator => { 0x06 } + Gamemode::Survival => 0x00, + Gamemode::Creative => 0x01, + Gamemode::Adventure => 0x02, + Gamemode::SurvivalSpectator => 0x03, + Gamemode::CreativeSpectator => 0x04, + Gamemode::Default => 0x05, + Gamemode::Spectator => 0x06, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto_core/src/types/generator_type.rs b/proto_core/src/types/generator_type.rs index 7b651459..94378abd 100644 --- a/proto_core/src/types/generator_type.rs +++ b/proto_core/src/types/generator_type.rs @@ -1,28 +1,30 @@ use std::sync::Arc; -use bedrock_core::{GeneratorType, LE, VAR}; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{GeneratorType, VAR}; + use crate::error::ProtoCodecError; use crate::ProtoCodec; impl ProtoCodec for GeneratorType { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { let int = match self { - GeneratorType::Legacy => { 0x00 } - GeneratorType::Overworld => { 0x01 } - GeneratorType::Flat => { 0x02 } - GeneratorType::Nether => { 0x03 } - GeneratorType::End => { 0x04 } - GeneratorType::Void => { 0x05 } + GeneratorType::Legacy => 0x00, + GeneratorType::Overworld => 0x01, + GeneratorType::Flat => 0x02, + GeneratorType::Nether => 0x03, + GeneratorType::End => 0x04, + GeneratorType::Void => 0x05, }; match VAR::::new(int).write(stream) { - Ok(_) => { Ok(()) } - Err(e) => { Err(ProtoCodecError::IOError(Arc::new(e))) } + Ok(_) => Ok(()), + Err(e) => Err(ProtoCodecError::IOError(Arc::new(e))), } } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { todo!() } -} \ No newline at end of file +} diff --git a/proto_core/src/types/mod.rs b/proto_core/src/types/mod.rs index 2f2b1e97..bbac692f 100644 --- a/proto_core/src/types/mod.rs +++ b/proto_core/src/types/mod.rs @@ -1,13 +1,13 @@ +mod actor_runtime_id; +mod actor_unique_id; pub mod bool; +mod difficulty; +mod dimension; +mod gamemode; +mod generator_type; pub mod int; +mod nbt_tag; pub mod option; pub mod string; -pub mod vec; -mod actor_runtime_id; -mod actor_unique_id; -mod gamemode; mod uuid; -mod nbt_tag; -mod difficulty; -mod generator_type; -mod dimension; +pub mod vec; diff --git a/proto_core/src/types/nbt_tag.rs b/proto_core/src/types/nbt_tag.rs index 4874a22e..c905a9d8 100644 --- a/proto_core/src/types/nbt_tag.rs +++ b/proto_core/src/types/nbt_tag.rs @@ -1,22 +1,25 @@ use std::io::Cursor; + use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; -use nbt::{NbtError, NbtTag}; use nbt::endian::little_endian_network::NbtLittleEndianNetwork; +use nbt::NbtTag; + use crate::error::ProtoCodecError; use crate::ProtoCodec; impl ProtoCodec for NbtTag { fn proto_serialize(&self, stream: &mut ByteStreamWrite) -> Result<(), ProtoCodecError> { - self.nbt_serialize::("", stream).map_err(|e| { ProtoCodecError::NbtError(e) }) + self.nbt_serialize::("", stream) + .map_err(|e| ProtoCodecError::NbtError(e)) } fn proto_deserialize(stream: &mut ByteStreamRead) -> Result { let mut cursor = Cursor::new(stream.get_ref().as_slice()); match NbtTag::nbt_deserialize::(&mut cursor) { - Ok((_, v)) => { Ok(v) } - Err(e) => { Err(ProtoCodecError::NbtError(e)) } + Ok((_, v)) => Ok(v), + Err(e) => Err(ProtoCodecError::NbtError(e)), } } -} \ No newline at end of file +} diff --git a/proto_core/src/types/uuid.rs b/proto_core/src/types/uuid.rs index dc9f8147..7320d3fe 100644 --- a/proto_core/src/types/uuid.rs +++ b/proto_core/src/types/uuid.rs @@ -1,6 +1,7 @@ -use bedrock_core::{LE, Uuid}; use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; +use bedrock_core::{Uuid, LE}; + use crate::error::ProtoCodecError; use crate::ProtoCodec; @@ -20,4 +21,4 @@ impl ProtoCodec for Uuid { Ok(Uuid::from_u64_pair(first, second)) } -} \ No newline at end of file +} diff --git a/proto_core/src/types/vec.rs b/proto_core/src/types/vec.rs index 37eb435e..66d91c4f 100644 --- a/proto_core/src/types/vec.rs +++ b/proto_core/src/types/vec.rs @@ -1,9 +1,6 @@ -use std::convert::TryInto; -use std::sync::Arc; - use bedrock_core::read::ByteStreamRead; use bedrock_core::write::ByteStreamWrite; -use bedrock_core::{Vec2, Vec2f, Vec3, Vec3f, LE, VAR}; +use bedrock_core::{Vec2, Vec2f, Vec3, Vec3f, LE}; use crate::error::ProtoCodecError; use crate::ProtoCodec;