cargo fmt

This commit is contained in:
Snowiiii 2024-08-14 21:37:27 +02:00
parent 5f8cbdbba6
commit 6485c99167
9 changed files with 36 additions and 32 deletions

View File

@ -8,9 +8,9 @@ pub mod bytebuf;
pub mod client; pub mod client;
pub mod packet_decoder; pub mod packet_decoder;
pub mod packet_encoder; pub mod packet_encoder;
pub mod position;
pub mod server; pub mod server;
pub mod uuid; pub mod uuid;
pub mod position;
pub const CURRENT_MC_PROTOCOL: u32 = 767; pub const CURRENT_MC_PROTOCOL: u32 = 767;

View File

@ -3,29 +3,31 @@ use serde::Deserialize;
pub struct WorldPosition { pub struct WorldPosition {
x: i32, x: i32,
y: i32, y: i32,
z: i32 z: i32,
} }
impl<'de> Deserialize<'de> for WorldPosition { impl<'de> Deserialize<'de> for WorldPosition {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: serde::Deserializer<'de> { D: serde::Deserializer<'de>,
struct Visitor; {
impl<'a> serde::de::Visitor<'a> for Visitor { struct Visitor;
type Value = WorldPosition; impl<'a> serde::de::Visitor<'a> for Visitor {
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { type Value = WorldPosition;
formatter.write_str("An i64 int") fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
} formatter.write_str("An i64 int")
fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E> }
where fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E>
E: serde::de::Error, { where
Ok(WorldPosition { E: serde::de::Error,
x: (v >> 38) as i32, {
y: (v << 52 >> 52) as i32, Ok(WorldPosition {
z: (v << 26 >> 38) as i32 x: (v >> 38) as i32,
}) y: (v << 52 >> 52) as i32,
} z: (v << 26 >> 38) as i32,
})
} }
deserializer.deserialize_i64(Visitor)
} }
} deserializer.deserialize_i64(Visitor)
}
}

View File

@ -3,21 +3,21 @@ mod c_interact;
mod s_chat_command; mod s_chat_command;
mod s_chat_message; mod s_chat_message;
mod s_confirm_teleport; mod s_confirm_teleport;
mod s_player_action;
mod s_player_command; mod s_player_command;
mod s_player_position; mod s_player_position;
mod s_player_position_rotation; mod s_player_position_rotation;
mod s_player_rotation; mod s_player_rotation;
mod s_swing_arm; mod s_swing_arm;
mod s_player_action;
pub use c_client_information::*; pub use c_client_information::*;
pub use c_interact::*; pub use c_interact::*;
pub use s_chat_command::*; pub use s_chat_command::*;
pub use s_chat_message::*; pub use s_chat_message::*;
pub use s_confirm_teleport::*; pub use s_confirm_teleport::*;
pub use s_player_action::*;
pub use s_player_command::*; pub use s_player_command::*;
pub use s_player_position::*; pub use s_player_position::*;
pub use s_player_position_rotation::*; pub use s_player_position_rotation::*;
pub use s_player_rotation::*; pub use s_player_rotation::*;
pub use s_swing_arm::*; pub use s_swing_arm::*;
pub use s_player_action::*;

View File

@ -9,4 +9,4 @@ pub struct SPlayerAction {
location: WorldPosition, location: WorldPosition,
face: u8, face: u8,
sequence: VarInt, sequence: VarInt,
} }

View File

@ -4,5 +4,5 @@ pub const WORLD_HEIGHT: usize = 384;
pub const WORLD_Y_START_AT: i32 = -64; pub const WORLD_Y_START_AT: i32 = -64;
pub const DIRECT_PALETTE_BITS: u32 = 15; pub const DIRECT_PALETTE_BITS: u32 = 15;
mod block_registry; mod block_registry;
pub mod radial_chunk_iterator;
mod world; mod world;
pub mod radial_chunk_iterator;

View File

@ -56,4 +56,4 @@ impl Iterator for RadialIterator {
self.steps_taken += 1; self.steps_taken += 1;
Some(result) Some(result)
} }
} }

View File

@ -89,7 +89,11 @@ impl Level {
region_file_path.push(format!("r.{}.{}.mca", region.0, region.1)); region_file_path.push(format!("r.{}.{}.mca", region.0, region.1));
// return different error when file is not found (because that means that the chunks have just not been generated yet) // return different error when file is not found (because that means that the chunks have just not been generated yet)
let mut region_file = match std::fs::File::options().read(true).write(false).open(&region_file_path) { let mut region_file = match std::fs::File::options()
.read(true)
.write(false)
.open(&region_file_path)
{
Ok(f) => f, Ok(f) => f,
Err(err) => match err.kind() { Err(err) => match err.kind() {
std::io::ErrorKind::NotFound => { std::io::ErrorKind::NotFound => {

View File

@ -1,17 +1,15 @@
use super::Command; use super::Command;
pub struct StopCommand { pub struct StopCommand {}
}
impl<'a> Command<'a> for StopCommand { impl<'a> Command<'a> for StopCommand {
const NAME: &'static str = "stop"; const NAME: &'static str = "stop";
const DESCRIPTION: &'static str = "Stops the server"; const DESCRIPTION: &'static str = "Stops the server";
fn on_execute(sender: &mut super::CommandSender<'a>, command: String) { fn on_execute(sender: &mut super::CommandSender<'a>, command: String) {
std::process::exit(0); std::process::exit(0);
} }
fn player_required() -> bool { fn player_required() -> bool {
true true
} }
} }

View File

@ -347,7 +347,7 @@ impl Server {
chunk_x: 0.into(), chunk_x: 0.into(),
chunk_z: 0.into(), chunk_z: 0.into(),
}); });
while let Some((chunk_pos, chunk_data)) = chunk_receiver.recv().await { while let Some((chunk_pos, chunk_data)) = chunk_receiver.recv().await {
// dbg!(chunk_pos); // dbg!(chunk_pos);
let chunk_data = match chunk_data { let chunk_data = match chunk_data {