diff --git a/pumpkin-data/build/build.rs b/pumpkin-data/build/build.rs index 799ba62bb..7b0342de0 100644 --- a/pumpkin-data/build/build.rs +++ b/pumpkin-data/build/build.rs @@ -48,12 +48,13 @@ mod world_event; pub const OUT_DIR: &str = "src/generated"; pub fn main() { - let path = Path::new(OUT_DIR); - if !path.exists() { - let _ = fs::create_dir(OUT_DIR); + if let Err(e) = fs::create_dir_all(OUT_DIR) { + eprintln!("Failed to create output directory {}: {}", OUT_DIR, e); } - #[allow(clippy::type_complexity)] - let build_functions: Vec<(fn() -> TokenStream, &str)> = vec![ + + type BuilderFn = fn() -> TokenStream; + + let build_functions: Vec<(BuilderFn, &str)> = vec![ (packet::build, "packet.rs"), (screen::build, "screen.rs"), (particle::build, "particle.rs"), @@ -97,22 +98,21 @@ pub fn main() { ]; build_functions.par_iter().for_each(|(build_fn, file)| { - let formatted_code = format_code(&build_fn().to_string()); - - write_generated_file(&formatted_code, file); + let raw_code = build_fn().to_string(); + let final_code = format_code(&raw_code); + write_generated_file(&final_code.unwrap_or(raw_code), file); }); } pub fn array_to_tokenstream(array: &[String]) -> TokenStream { - let mut variants = TokenStream::new(); - - for item in array.iter() { + let variants = array.iter().map(|item| { let name = format_ident!("{}", item.to_pascal_case()); - variants.extend([quote! { - #name, - }]); + quote! { #name, } + }); + + quote! { + #(#variants)* } - variants } pub fn write_generated_file(new_code: &str, out_file: &str) { @@ -122,39 +122,38 @@ pub fn write_generated_file(new_code: &str, out_file: &str) { && let Ok(existing_code) = fs::read_to_string(&path) && existing_code == new_code { - return; // No changes, so we skip writing. + return; } fs::write(&path, new_code) .unwrap_or_else(|_| panic!("Failed to write to file: {}", path.display())); } -pub fn format_code(unformatted_code: &str) -> String { - let mut child = Command::new("rustfmt") +pub struct RustFmtError; + +pub fn format_code(unformatted_code: &str) -> Result { + let child_result = Command::new("rustfmt") .stdin(Stdio::piped()) .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("Failed to spawn rustfmt process."); + .stderr(Stdio::null()) + .spawn(); - child - .stdin - .take() - .expect("Failed to take rustfmt stdin") - .write_all(unformatted_code.as_bytes()) - .expect("Failed to write to rustfmt stdin."); + let mut child = match child_result { + Ok(c) => c, + Err(_) => return Err(RustFmtError), + }; - let output = child - .wait_with_output() - .expect("Failed to wait for rustfmt process."); + // Write the code to rustfmt's stdin + if let Some(mut stdin) = child.stdin.take() + && stdin.write_all(unformatted_code.as_bytes()).is_err() + { + return Err(RustFmtError); + } - if output.status.success() { - String::from_utf8(output.stdout).expect("rustfmt output was not valid UTF-8.") - } else { - panic!( - "rustfmt failed with status: {}\n--- stderr ---\n{}", - output.status, - String::from_utf8_lossy(&output.stderr) - ); + match child.wait_with_output() { + Ok(output) if output.status.success() => { + String::from_utf8(output.stdout).map_err(|_| RustFmtError) + } + _ => Err(RustFmtError), } } diff --git a/pumpkin-protocol/src/serial/mod.rs b/pumpkin-protocol/src/serial/mod.rs index 7607e65cc..db0d228ca 100644 --- a/pumpkin-protocol/src/serial/mod.rs +++ b/pumpkin-protocol/src/serial/mod.rs @@ -6,13 +6,13 @@ use std::io::{Error, Read, Write}; pub trait PacketWrite { fn write(&self, writer: &mut W) -> Result<(), Error>; fn write_be(&self, _writer: &mut W) -> Result<(), Error> { - panic!("not implemented") + todo!() } } pub trait PacketRead: Sized { fn read(reader: &mut R) -> Result; fn read_be(_reader: &mut R) -> Result { - panic!("not implemented") + todo!() } } diff --git a/pumpkin/src/command/client_suggestions.rs b/pumpkin/src/command/client_suggestions.rs index 209295a3f..a3e788dc3 100644 --- a/pumpkin/src/command/client_suggestions.rs +++ b/pumpkin/src/command/client_suggestions.rs @@ -54,7 +54,7 @@ pub async fn send_c_commands_packet(player: &Arc, dispatcher: &CommandDi #[derive(Debug)] struct ProtoNodeBuilder<'a> { - child_nodes: Vec>, + child_nodes: Vec, node_type: ProtoNodeType<'a>, } diff --git a/pumpkin/src/command/tree/builder.rs b/pumpkin/src/command/tree/builder.rs index c1095a7c0..35bfc6b51 100644 --- a/pumpkin/src/command/tree/builder.rs +++ b/pumpkin/src/command/tree/builder.rs @@ -73,7 +73,7 @@ impl NodeBuilder for LeafNodeBuilder { pub struct NonLeafNodeBuilder { node_type: NodeType, - child_nodes: Vec, + child_nodes: Vec, leaf_nodes: Vec, } diff --git a/pumpkin/src/net/bedrock/mod.rs b/pumpkin/src/net/bedrock/mod.rs index 7edc5b434..ecae087c0 100644 --- a/pumpkin/src/net/bedrock/mod.rs +++ b/pumpkin/src/net/bedrock/mod.rs @@ -66,7 +66,7 @@ pub struct BedrockClient { pub player: Mutex>>, /// All Bedrock clients /// This list is used to remove the client if the connection gets closed - pub be_clients: Arc>>>, + pub be_clients: Arc>>>, tasks: TaskTracker, outgoing_packet_queue_send: Sender, diff --git a/pumpkin/src/plugin/mod.rs b/pumpkin/src/plugin/mod.rs index baaa7393a..6c63be187 100644 --- a/pumpkin/src/plugin/mod.rs +++ b/pumpkin/src/plugin/mod.rs @@ -137,7 +137,7 @@ pub struct PluginManager { handlers: Arc>, unloaded_files: RwLock>, // Self-reference for sharing with contexts - self_ref: RwLock>>, + self_ref: RwLock>>, services: Arc>>>, // Plugin state tracking plugin_states: RwLock>, diff --git a/pumpkin/src/world/natural_spawner.rs b/pumpkin/src/world/natural_spawner.rs index c52750375..c4b2e75d6 100644 --- a/pumpkin/src/world/natural_spawner.rs +++ b/pumpkin/src/world/natural_spawner.rs @@ -366,7 +366,7 @@ pub async fn spawn_category_for_position( let mut random_group_size = (rng().random::() * 4.).ceil() as i32; let mut inc = 0; #[allow(unused_variables)] - let mut group_size = 0; + let group_size = 0; 'outer: while inc < random_group_size { new_x += rng().random_range(0..6) - rng().random_range(0..6); new_z += rng().random_range(0..6) - rng().random_range(0..6); @@ -419,7 +419,7 @@ pub async fn spawn_category_for_position( // TODO isValidPositionForMob(level, mob, f) // TODO spawnGroupData = mob.finalizeSpawn(level, level.getCurrentDifficultyAt(mob.blockPosition()), EntitySpawnReason.NATURAL, spawnGroupData); spawn_cluster_size += 1; - group_size += 1; + //group_size += 1; world.spawn_entity(entity).await; spawn_state.after_spawn(entity_type, &new_pos, world).await; if spawn_cluster_size >= entity_type.limit_per_chunk {