diff --git a/src/lua/client/world/mod.rs b/src/lua/client/world/mod.rs index 721b271..5355fc6 100644 --- a/src/lua/client/world/mod.rs +++ b/src/lua/client/world/mod.rs @@ -32,21 +32,20 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result Result> { - #[allow(clippy::cast_possible_truncation)] - Ok( - if let Some(state) = client.world().read().get_fluid_state(&BlockPos::new( - position.x as i32, - position.y as i32, - position.z as i32, - )) { - let table = lua.create_table()?; - table.set("kind", state.kind as u8)?; - table.set("amount", state.amount)?; - table.set("falling", state.falling)?; - Some(table) - } else { - None - }, - ) + let fluid_state = client.world().read().get_fluid_state(&BlockPos::new( + position.x as i32, + position.y as i32, + position.z as i32, + )); + Ok(if let Some(state) = fluid_state { + let table = lua.create_table()?; + table.set("kind", state.kind as u8)?; + table.set("amount", state.amount)?; + table.set("falling", state.falling)?; + Some(table) + } else { + None + }) } diff --git a/src/lua/container/item_stack.rs b/src/lua/container/item_stack.rs index bb9f47b..e75caba 100644 --- a/src/lua/container/item_stack.rs +++ b/src/lua/container/item_stack.rs @@ -71,9 +71,7 @@ impl UserData for ItemStack { } fn add_methods>(m: &mut M) { - m.add_method_mut("split", |_, this, count: u32| { - Ok(ItemStack(this.0.split(count))) - }); + m.add_method_mut("split", |_, this, count: u32| Ok(Self(this.0.split(count)))); m.add_method_mut("update_empty", |_, this, (): ()| { this.0.update_empty(); Ok(()) diff --git a/src/lua/events.rs b/src/lua/events.rs index 0355adb..11bb682 100644 --- a/src/lua/events.rs +++ b/src/lua/events.rs @@ -13,13 +13,15 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap move |_, (event_type, callback, optional_id): (String, Function, Option)| { let m = m.clone(); let id = optional_id.unwrap_or_else(|| { - callback.info().name.unwrap_or(format!( - "anonymous @ {}", - SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap_or_default() - .as_millis() - )) + callback.info().name.unwrap_or_else(|| { + format!( + "anonymous @ {}", + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_millis() + ) + }) }); tokio::spawn(async move { m.write() @@ -40,12 +42,10 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap let m = m.clone(); tokio::spawn(async move { let mut m = m.write().await; - let empty = if let Some(listeners) = m.get_mut(&event_type) { + let empty = m.get_mut(&event_type).is_some_and(|listeners| { listeners.retain(|(id, _)| target_id != *id); listeners.is_empty() - } else { - false - }; + }); if empty { m.remove(&event_type); } diff --git a/src/lua/matrix/room.rs b/src/lua/matrix/room.rs index 1517a24..9937b76 100644 --- a/src/lua/matrix/room.rs +++ b/src/lua/matrix/room.rs @@ -37,12 +37,7 @@ impl UserData for Room { .members(RoomMemberships::all()) .await .map_err(Error::external) - .map(|members| { - members - .into_iter() - .map(|member| Member(member.clone())) - .collect::>() - }) + .map(|members| members.into_iter().map(Member).collect::>()) }); m.add_async_method( "kick_user", diff --git a/src/lua/mod.rs b/src/lua/mod.rs index e3a030d..d60ff2f 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -38,12 +38,12 @@ impl Display for Error { formatter, "failed to {}", match self { - Error::CreateEnv(error) => format!("create environment: {error}"), - Error::EvalChunk(error) => format!("evaluate chunk: {error}"), - Error::ExecChunk(error) => format!("execute chunk: {error}"), - Error::LoadChunk(error) => format!("load chunk: {error}"), - Error::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"), - Error::ReadFile(error) => format!("read script file: {error}"), + Self::CreateEnv(error) => format!("create environment: {error}"), + Self::EvalChunk(error) => format!("evaluate chunk: {error}"), + Self::ExecChunk(error) => format!("execute chunk: {error}"), + Self::LoadChunk(error) => format!("load chunk: {error}"), + Self::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"), + Self::ReadFile(error) => format!("read script file: {error}"), } ) } diff --git a/src/lua/vec3.rs b/src/lua/vec3.rs index bb397c2..a2a849a 100644 --- a/src/lua/vec3.rs +++ b/src/lua/vec3.rs @@ -40,7 +40,7 @@ impl From<&Position> for Vec3 { impl From for Vec3 { fn from(p: BlockPos) -> Self { - Vec3 { + Self { x: f64::from(p.x), y: f64::from(p.y), z: f64::from(p.z), diff --git a/src/main.rs b/src/main.rs index f00a525..ef362e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ #![feature(if_let_guard, let_chains)] +#![warn(clippy::pedantic, clippy::nursery)] +#![allow(clippy::significant_drop_tightening)] mod arguments; mod build_info; diff --git a/src/particle.rs b/src/particle.rs index 2053286..cb17005 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -1,7 +1,7 @@ use azalea::{entity::particle::Particle, registry::ParticleKind}; #[allow(clippy::too_many_lines)] -pub fn to_kind(particle: &Particle) -> ParticleKind { +pub const fn to_kind(particle: &Particle) -> ParticleKind { match particle { Particle::AngryVillager => ParticleKind::AngryVillager, Particle::Block(_) => ParticleKind::Block, diff --git a/src/replay/plugin.rs b/src/replay/plugin.rs index e919db3..e304565 100644 --- a/src/replay/plugin.rs +++ b/src/replay/plugin.rs @@ -12,7 +12,7 @@ use azalea::{ protocol::packets::login::ClientboundLoginPacket, raw_connection::RawConnection, }; -use bevy_app::{First, Plugin}; +use bevy_app::{App, First, Plugin}; use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut}; use log::error; use parking_lot::Mutex; @@ -24,8 +24,9 @@ pub struct RecordPlugin { } impl Plugin for RecordPlugin { - fn build(&self, app: &mut bevy_app::App) { - if let Some(recorder) = self.recorder.lock().take() { + fn build(&self, app: &mut App) { + let recorder = self.recorder.lock().take(); + if let Some(recorder) = recorder { app.insert_resource(recorder) .add_systems(First, record_login_packets.before(process_packet_events)) .add_systems(First, record_configuration_packets)