refactor: cargo clippy improvements

This commit is contained in:
Ryan 2025-04-14 23:34:19 -04:00
parent 85e1f082a7
commit f9495a36f2
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
9 changed files with 42 additions and 47 deletions

View File

@ -32,21 +32,20 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
.map(|block| block.id)) .map(|block| block.id))
} }
#[allow(clippy::cast_possible_truncation)]
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> { pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
#[allow(clippy::cast_possible_truncation)] let fluid_state = client.world().read().get_fluid_state(&BlockPos::new(
Ok( position.x as i32,
if let Some(state) = client.world().read().get_fluid_state(&BlockPos::new( position.y as i32,
position.x as i32, position.z as i32,
position.y as i32, ));
position.z as i32, Ok(if let Some(state) = fluid_state {
)) { let table = lua.create_table()?;
let table = lua.create_table()?; table.set("kind", state.kind as u8)?;
table.set("kind", state.kind as u8)?; table.set("amount", state.amount)?;
table.set("amount", state.amount)?; table.set("falling", state.falling)?;
table.set("falling", state.falling)?; Some(table)
Some(table) } else {
} else { None
None })
},
)
} }

View File

@ -71,9 +71,7 @@ impl UserData for ItemStack {
} }
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) { fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
m.add_method_mut("split", |_, this, count: u32| { m.add_method_mut("split", |_, this, count: u32| Ok(Self(this.0.split(count))));
Ok(ItemStack(this.0.split(count)))
});
m.add_method_mut("update_empty", |_, this, (): ()| { m.add_method_mut("update_empty", |_, this, (): ()| {
this.0.update_empty(); this.0.update_empty();
Ok(()) Ok(())

View File

@ -13,13 +13,15 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
move |_, (event_type, callback, optional_id): (String, Function, Option<String>)| { move |_, (event_type, callback, optional_id): (String, Function, Option<String>)| {
let m = m.clone(); let m = m.clone();
let id = optional_id.unwrap_or_else(|| { let id = optional_id.unwrap_or_else(|| {
callback.info().name.unwrap_or(format!( callback.info().name.unwrap_or_else(|| {
"anonymous @ {}", format!(
SystemTime::now() "anonymous @ {}",
.duration_since(UNIX_EPOCH) SystemTime::now()
.unwrap_or_default() .duration_since(UNIX_EPOCH)
.as_millis() .unwrap_or_default()
)) .as_millis()
)
})
}); });
tokio::spawn(async move { tokio::spawn(async move {
m.write() m.write()
@ -40,12 +42,10 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
let m = m.clone(); let m = m.clone();
tokio::spawn(async move { tokio::spawn(async move {
let mut m = m.write().await; 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.retain(|(id, _)| target_id != *id);
listeners.is_empty() listeners.is_empty()
} else { });
false
};
if empty { if empty {
m.remove(&event_type); m.remove(&event_type);
} }

View File

@ -37,12 +37,7 @@ impl UserData for Room {
.members(RoomMemberships::all()) .members(RoomMemberships::all())
.await .await
.map_err(Error::external) .map_err(Error::external)
.map(|members| { .map(|members| members.into_iter().map(Member).collect::<Vec<_>>())
members
.into_iter()
.map(|member| Member(member.clone()))
.collect::<Vec<_>>()
})
}); });
m.add_async_method( m.add_async_method(
"kick_user", "kick_user",

View File

@ -38,12 +38,12 @@ impl Display for Error {
formatter, formatter,
"failed to {}", "failed to {}",
match self { match self {
Error::CreateEnv(error) => format!("create environment: {error}"), Self::CreateEnv(error) => format!("create environment: {error}"),
Error::EvalChunk(error) => format!("evaluate chunk: {error}"), Self::EvalChunk(error) => format!("evaluate chunk: {error}"),
Error::ExecChunk(error) => format!("execute chunk: {error}"), Self::ExecChunk(error) => format!("execute chunk: {error}"),
Error::LoadChunk(error) => format!("load chunk: {error}"), Self::LoadChunk(error) => format!("load chunk: {error}"),
Error::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"), Self::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
Error::ReadFile(error) => format!("read script file: {error}"), Self::ReadFile(error) => format!("read script file: {error}"),
} }
) )
} }

View File

@ -40,7 +40,7 @@ impl From<&Position> for Vec3 {
impl From<BlockPos> for Vec3 { impl From<BlockPos> for Vec3 {
fn from(p: BlockPos) -> Self { fn from(p: BlockPos) -> Self {
Vec3 { Self {
x: f64::from(p.x), x: f64::from(p.x),
y: f64::from(p.y), y: f64::from(p.y),
z: f64::from(p.z), z: f64::from(p.z),

View File

@ -1,4 +1,6 @@
#![feature(if_let_guard, let_chains)] #![feature(if_let_guard, let_chains)]
#![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::significant_drop_tightening)]
mod arguments; mod arguments;
mod build_info; mod build_info;

View File

@ -1,7 +1,7 @@
use azalea::{entity::particle::Particle, registry::ParticleKind}; use azalea::{entity::particle::Particle, registry::ParticleKind};
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
pub fn to_kind(particle: &Particle) -> ParticleKind { pub const fn to_kind(particle: &Particle) -> ParticleKind {
match particle { match particle {
Particle::AngryVillager => ParticleKind::AngryVillager, Particle::AngryVillager => ParticleKind::AngryVillager,
Particle::Block(_) => ParticleKind::Block, Particle::Block(_) => ParticleKind::Block,

View File

@ -12,7 +12,7 @@ use azalea::{
protocol::packets::login::ClientboundLoginPacket, protocol::packets::login::ClientboundLoginPacket,
raw_connection::RawConnection, raw_connection::RawConnection,
}; };
use bevy_app::{First, Plugin}; use bevy_app::{App, First, Plugin};
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut}; use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut};
use log::error; use log::error;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -24,8 +24,9 @@ pub struct RecordPlugin {
} }
impl Plugin for RecordPlugin { impl Plugin for RecordPlugin {
fn build(&self, app: &mut bevy_app::App) { fn build(&self, app: &mut App) {
if let Some(recorder) = self.recorder.lock().take() { let recorder = self.recorder.lock().take();
if let Some(recorder) = recorder {
app.insert_resource(recorder) app.insert_resource(recorder)
.add_systems(First, record_login_packets.before(process_packet_events)) .add_systems(First, record_login_packets.before(process_packet_events))
.add_systems(First, record_configuration_packets) .add_systems(First, record_configuration_packets)