Skip to content

Commit

Permalink
rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
theaddonn committed Aug 2, 2024
1 parent 51698e4 commit 53c7a7b
Show file tree
Hide file tree
Showing 35 changed files with 211 additions and 202 deletions.
2 changes: 1 addition & 1 deletion core/src/vec/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
};

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::int::{BE, LE, VAR};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Vec2<T> {
Expand Down
5 changes: 2 additions & 3 deletions core/src/vec/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
};

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::int::{BE, LE, VAR};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Vec3<T> {
Expand Down Expand Up @@ -157,7 +157,6 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Vec3<T> {
}
}


impl<T> Vec3<T> {
// LE
#[inline]
Expand Down Expand Up @@ -215,4 +214,4 @@ impl<T> Vec3<T> {
z: var.z.into_inner(),
}
}
}
}
6 changes: 4 additions & 2 deletions form/src/elems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde_json::Value;
use crate::error::FormError;
use serde_json::Value;

pub mod button;
pub mod dropdown;
Expand All @@ -11,5 +11,7 @@ pub mod toggle;

pub trait Element {
fn elem_serialize(&self) -> Value;
fn elem_deserialize(elem_json: Value) -> Result<Self, FormError> where Self: Sized;
fn elem_deserialize(elem_json: Value) -> Result<Self, FormError>
where
Self: Sized;
}
4 changes: 1 addition & 3 deletions form/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use thiserror::Error;

#[derive(Error, Debug, Clone)]
pub enum FormError {

}
pub enum FormError {}
2 changes: 1 addition & 1 deletion form/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use window::*;

pub mod elems;
pub mod window;
pub mod error;
pub mod window;
4 changes: 3 additions & 1 deletion form/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ pub mod simple;

pub trait Form {
fn form_serialize(&self) -> String;
fn form_deserialize(form_json: &str) -> Result<Self, FormError> where Self: Sized;
fn form_deserialize(form_json: &str) -> Result<Self, FormError>
where
Self: Sized;
}
32 changes: 14 additions & 18 deletions proto/src/gamepacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
use std::io::{Cursor, Write};
use std::sync::Arc;

use bedrockrs_core::int::VAR;
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;
use crate::packets::animate::AnimatePacket;
use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket;
use crate::packets::client_cache_status::ClientCacheStatusPacket;
use crate::packets::disconnect::DisconnectPacket;
use crate::packets::emote_list::EmoteListPacket;
Expand All @@ -21,6 +19,7 @@ use crate::packets::network_settings_request::NetworkSettingsRequestPacket;
use crate::packets::packet_violation_warning::PacketViolationWarningPacket;
use crate::packets::play_status::PlayStatusPacket;
use crate::packets::player_auth_input::PlayerAuthInputPacket;
use crate::packets::player_move::MovePlayerPacket;
use crate::packets::request_chunk_radius::RequestChunkRadiusPacket;
use crate::packets::resource_packs_info::ResourcePacksInfoPacket;
use crate::packets::resource_packs_response::ResourcePacksResponsePacket;
Expand All @@ -29,9 +28,10 @@ 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::start_game::StartGamePacket;
use crate::packets::player_move::MovePlayerPacket;
use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket;
use crate::packets::text_message::TextMessagePacket;
use bedrockrs_core::int::VAR;
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;

#[repr(u16)]
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -965,9 +965,7 @@ impl GamePacket {
GamePacket::MobArmorEquipmentID => {
unimplemented!()
}
GamePacket::InteractID => {
GamePacket::Interact(de_packet!(stream, InteractPacket))
}
GamePacket::InteractID => GamePacket::Interact(de_packet!(stream, InteractPacket)),
GamePacket::BlockPickRequestID => {
unimplemented!()
}
Expand Down Expand Up @@ -995,9 +993,7 @@ impl GamePacket {
GamePacket::SetSpawnPositionID => {
unimplemented!()
}
GamePacket::AnimateID => {
GamePacket::Animate(de_packet!(stream, AnimatePacket))
}
GamePacket::AnimateID => GamePacket::Animate(de_packet!(stream, AnimatePacket)),
GamePacket::RespawnID => {
unimplemented!()
}
Expand Down Expand Up @@ -1070,7 +1066,9 @@ impl GamePacket {
GamePacket::MapInfoRequestID => {
unimplemented!()
}
GamePacket::RequestChunkRadiusID => GamePacket::RequestChunkRadius(de_packet!(stream, RequestChunkRadiusPacket)),
GamePacket::RequestChunkRadiusID => {
GamePacket::RequestChunkRadius(de_packet!(stream, RequestChunkRadiusPacket))
}
GamePacket::ChunkRadiusUpdateID => {
unimplemented!()
}
Expand Down Expand Up @@ -1200,9 +1198,9 @@ impl GamePacket {
GamePacket::SetScoreboardIdentityID => {
unimplemented!()
}
GamePacket::SetLocalPlayerAsInitializedID => {
GamePacket::SetLocalPlayerAsInitialized(de_packet!(stream, SetLocalPlayerAsInitializedPacket))
}
GamePacket::SetLocalPlayerAsInitializedID => GamePacket::SetLocalPlayerAsInitialized(
de_packet!(stream, SetLocalPlayerAsInitializedPacket),
),
GamePacket::UpdateSoftEnumID => {
unimplemented!()
}
Expand Down Expand Up @@ -1284,9 +1282,7 @@ impl GamePacket {
GamePacket::UpdatePlayerGameTypeID => {
unimplemented!()
}
GamePacket::EmoteListID => {
GamePacket::EmoteList(de_packet!(stream, EmoteListPacket))
}
GamePacket::EmoteListID => GamePacket::EmoteList(de_packet!(stream, EmoteListPacket)),
GamePacket::PacketViolationWarningID => {
GamePacket::PacketViolationWarning(de_packet!(stream, PacketViolationWarningPacket))
}
Expand Down
22 changes: 14 additions & 8 deletions proto/src/login/start_game.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use bedrockrs_core::int::{LE, VAR};
use bedrockrs_core::{Vec2, Vec3};
use bedrockrs_nbt::NbtTag;
use std::collections::HashMap;
use uuid::Uuid;

use bedrockrs_shared::actor_runtime_id::ActorRuntimeID;
Expand All @@ -15,6 +15,7 @@ use crate::connection::ConnectionShard;
use crate::error::LoginError;
use crate::gamepacket::GamePacket;
use crate::login::provider::LoginProviderServer;
use crate::packets::play_status::PlayStatusPacket;
use crate::packets::start_game::StartGamePacket;
use crate::types::base_game_version::BaseGameVersion;
use crate::types::chat_restriction_level::ChatRestrictionLevel;
Expand All @@ -23,13 +24,12 @@ use crate::types::experiments::Experiments;
use crate::types::level_settings::LevelSettings;
use crate::types::network_block_pos::NetworkBlockPos;
use crate::types::network_permissions::NetworkPermissions;
use crate::types::play_status::PlayStatusType;
use crate::types::player_movement_mode::PlayerMovementMode;
use crate::types::player_movement_settings::PlayerMovementSettings;
use crate::types::spawn_biome_type::SpawnBiomeType;
use crate::types::spawn_settings::SpawnSettings;
use bedrockrs_shared::world::editor_world_type::EditorWorldType;
use crate::packets::play_status::PlayStatusPacket;
use crate::types::play_status::PlayStatusType;

pub async fn start_game(
conn: &mut ConnectionShard,
Expand Down Expand Up @@ -147,11 +147,17 @@ pub async fn start_game(
},
};

conn.send(GamePacket::StartGame(start_game)).await.map_err(|e| LoginError::ConnectionError(e))?;
conn.send(GamePacket::PlayStatus(PlayStatusPacket{
status: PlayStatusType::PlayerSpawn
})).await.map_err(|e| LoginError::ConnectionError(e))?;
conn.flush().await.map_err(|e| LoginError::ConnectionError(e))?;
conn.send(GamePacket::StartGame(start_game))
.await
.map_err(|e| LoginError::ConnectionError(e))?;
conn.send(GamePacket::PlayStatus(PlayStatusPacket {
status: PlayStatusType::PlayerSpawn,
}))
.await
.map_err(|e| LoginError::ConnectionError(e))?;
conn.flush()
.await
.map_err(|e| LoginError::ConnectionError(e))?;

Ok(())
}
19 changes: 12 additions & 7 deletions proto/src/packets/animate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::io::Cursor;
use crate::types::animate_action::AnimateAction;
use bedrockrs_core::int::{LE, VAR};
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;
use bedrockrs_shared::actor_runtime_id::ActorRuntimeID;
use crate::types::animate_action::AnimateAction;
use std::io::Cursor;

#[derive(Debug, Clone)]
pub struct AnimatePacket {
Expand All @@ -28,7 +28,7 @@ impl ProtoCodec for AnimatePacket {

if let AnimateAction::Swing { rowing_time } = self.action {
LE::new(rowing_time).proto_serialize(stream)?;
}
}

Ok(())
}
Expand All @@ -44,20 +44,25 @@ impl ProtoCodec for AnimatePacket {
let rowing_time = LE::<f32>::proto_deserialize(stream)?.into_inner();

AnimateAction::Swing { rowing_time }
},
}
3 => AnimateAction::WakeUp,
4 => AnimateAction::CriticalHit,
5 => AnimateAction::MagicCriticalHit,
128 => AnimateAction::RowRight,
129 => AnimateAction::RowLeft,
other => return Err(ProtoCodecError::InvalidEnumID(format!("{other:?}"), String::from("AnimateAction"))),
other => {
return Err(ProtoCodecError::InvalidEnumID(
format!("{other:?}"),
String::from("AnimateAction"),
))
}
};

println!("{:?}", &stream.get_ref()[(stream.position() as usize)..]);

Ok(Self{
Ok(Self {
action,
target_runtime_id
target_runtime_id,
})
}
}
4 changes: 2 additions & 2 deletions proto/src/packets/chunk_radius_updated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bedrockrs_core::int::{VAR, LE};
use bedrockrs_core::int::{LE, VAR};
use bedrockrs_proto_derive::ProtoCodec;

#[derive(ProtoCodec, Debug, Clone)]
pub struct ChunkRadiusUpdatedPacket {
pub chunk_radius: VAR<u32>
pub chunk_radius: VAR<u32>,
}
2 changes: 1 addition & 1 deletion proto/src/packets/disconnect.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::io::Cursor;

use crate::types::disconnect_reason::DisconnectReason;
use bedrockrs_core::int::VAR;
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;
use crate::types::disconnect_reason::DisconnectReason;

#[derive(Debug, Clone)]
pub struct DisconnectPacket {
Expand Down
4 changes: 2 additions & 2 deletions proto/src/packets/emote_list.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bedrockrs_core::int::VAR;
use bedrockrs_proto_derive::ProtoCodec;
use bedrockrs_shared::actor_runtime_id::ActorRuntimeID;
use uuid::Uuid;
use bedrockrs_core::int::VAR;

#[derive(ProtoCodec, Debug, Clone)]
pub struct EmoteListPacket {
runtime_id: ActorRuntimeID,
#[len_repr(VAR::<u32>)]
emote_piece_ids: Vec<Uuid>
emote_piece_ids: Vec<Uuid>,
}
25 changes: 12 additions & 13 deletions proto/src/packets/interact.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::io::Cursor;
use crate::types::interact_action::InteractAction;
use bedrockrs_core::int::LE;
use bedrockrs_core::Vec3;
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;
use bedrockrs_shared::actor_runtime_id::ActorRuntimeID;
use crate::types::interact_action::InteractAction;
use std::io::Cursor;

#[derive(Debug, Clone)]
pub struct InteractPacket {
action: InteractAction,
target_runtime_id: ActorRuntimeID
target_runtime_id: ActorRuntimeID,
}

impl ProtoCodec for InteractPacket {
Expand Down Expand Up @@ -37,9 +37,7 @@ impl ProtoCodec for InteractPacket {
let target_runtime_id = ActorRuntimeID::proto_deserialize(stream)?;

let action = match action {
0 => {
InteractAction::Invalid
}
0 => InteractAction::Invalid,
3 => {
let pos = Vec3::<LE<f32>>::proto_deserialize(stream)?;
let pos = Vec3::<f32>::from_le(pos);
Expand All @@ -52,18 +50,19 @@ impl ProtoCodec for InteractPacket {

InteractAction::InteractUpdate(pos)
}
5 => {
InteractAction::NpcOpen
}
6 => {
InteractAction::OpenInventory
5 => InteractAction::NpcOpen,
6 => InteractAction::OpenInventory,
other => {
return Err(ProtoCodecError::InvalidEnumID(
format!("{other:?}"),
String::from("InteractAction"),
))
}
other => return Err(ProtoCodecError::InvalidEnumID(format!("{other:?}"), String::from("InteractAction"))),
};

Ok(Self {
action,
target_runtime_id
target_runtime_id,
})
}
}
Loading

0 comments on commit 53c7a7b

Please sign in to comment.