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))
}
#[allow(clippy::cast_possible_truncation)]
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
#[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
})
}

View File

@ -71,9 +71,7 @@ impl UserData for ItemStack {
}
fn add_methods<M: UserDataMethods<Self>>(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(())

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>)| {
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);
}

View File

@ -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::<Vec<_>>()
})
.map(|members| members.into_iter().map(Member).collect::<Vec<_>>())
});
m.add_async_method(
"kick_user",

View File

@ -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}"),
}
)
}

View File

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

View File

@ -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;

View File

@ -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,

View File

@ -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)