From de7b3aa2ea69436f15bb87397e02c1b7ce30114d Mon Sep 17 00:00:00 2001 From: Alexander Medvedev <71594357+Snowiiii@users.noreply.github.com> Date: Mon, 19 Aug 2024 20:08:02 +0100 Subject: [PATCH] Fix: all clippy warns --- pumpkin-inventory/src/player.rs | 3 +- .../src/client/config/c_plugin_message.rs | 1 - .../src/client/play/c_chunk_data.rs | 6 ++-- .../src/client/play/c_particle.rs | 1 + pumpkin-protocol/src/packet_encoder.rs | 4 +-- .../src/server/play/s_interact.rs | 3 +- .../src/server/play/s_player_action.rs | 1 + .../src/server/play/s_player_command.rs | 1 - .../src/server/play/s_set_creative_slot.rs | 1 + pumpkin-protocol/src/slot.rs | 1 + pumpkin-text/src/click.rs | 2 +- pumpkin-world/src/chunk.rs | 29 ++----------------- pumpkin-world/src/global_registry.rs | 1 + pumpkin-world/src/item/item_registry.rs | 2 ++ pumpkin-world/src/world.rs | 6 ++-- pumpkin/src/client/client_packet.rs | 14 +++++---- pumpkin/src/client/player_packet.rs | 5 ++-- pumpkin/src/commands/stop.rs | 2 +- pumpkin/src/entity/player.rs | 1 - pumpkin/src/main.rs | 2 ++ pumpkin/src/rcon/packet.rs | 2 +- 21 files changed, 35 insertions(+), 53 deletions(-) diff --git a/pumpkin-inventory/src/player.rs b/pumpkin-inventory/src/player.rs index 08a464e8..3108b23f 100644 --- a/pumpkin-inventory/src/player.rs +++ b/pumpkin-inventory/src/player.rs @@ -1,5 +1,6 @@ use pumpkin_world::item::Item; +#[allow(dead_code)] pub struct PlayerInventory { // Main Inventory + Hotbar items: [Option; 36], @@ -26,7 +27,7 @@ impl PlayerInventory { } } - pub fn set_slot(slot: u32, item: Item) {} + pub fn set_slot(_slot: u32, _item: Item) {} pub fn set_selected(&mut self, slot: i16) { assert!((0..9).contains(&slot)); diff --git a/pumpkin-protocol/src/client/config/c_plugin_message.rs b/pumpkin-protocol/src/client/config/c_plugin_message.rs index 01f40580..c320ca29 100644 --- a/pumpkin-protocol/src/client/config/c_plugin_message.rs +++ b/pumpkin-protocol/src/client/config/c_plugin_message.rs @@ -1,7 +1,6 @@ use pumpkin_macros::packet; use serde::Serialize; - #[derive(Serialize)] #[packet(0x01)] pub struct CPluginMessage<'a> { diff --git a/pumpkin-protocol/src/client/play/c_chunk_data.rs b/pumpkin-protocol/src/client/play/c_chunk_data.rs index eec44e47..484be4fd 100644 --- a/pumpkin-protocol/src/client/play/c_chunk_data.rs +++ b/pumpkin-protocol/src/client/play/c_chunk_data.rs @@ -32,7 +32,7 @@ impl<'a> ClientPacket for CChunkData<'a> { data_buf.put_i16(block_count); //// Block states - let palette = chunk.into_iter().dedup().collect_vec(); + let palette = chunk.iter().dedup().collect_vec(); // TODO: make dynamic block_size work // TODO: make direct block_size work enum PaletteType { @@ -63,7 +63,7 @@ impl<'a> ClientPacket for CChunkData<'a> { palette.iter().enumerate().for_each(|(i, id)| { palette_map.insert(*id, i); // Palette - data_buf.put_var_int(&VarInt(**id as i32)); + data_buf.put_var_int(&VarInt(**id)); }); for block_clump in chunk.chunks(64 / block_size as usize) { let mut out_long: i64 = 0; @@ -109,7 +109,7 @@ impl<'a> ClientPacket for CChunkData<'a> { // Size buf.put_var_int(&VarInt(data_buf.buf().len() as i32)); // Data - buf.put_slice(&data_buf.buf()); + buf.put_slice(data_buf.buf()); // TODO: block entities buf.put_var_int(&VarInt(0)); diff --git a/pumpkin-protocol/src/client/play/c_particle.rs b/pumpkin-protocol/src/client/play/c_particle.rs index 5ef4f1b9..c3fa35a1 100644 --- a/pumpkin-protocol/src/client/play/c_particle.rs +++ b/pumpkin-protocol/src/client/play/c_particle.rs @@ -21,6 +21,7 @@ pub struct CParticle<'a> { } impl<'a> CParticle<'a> { + #[allow(clippy::too_many_arguments)] pub fn new( long_distance: bool, x: f64, diff --git a/pumpkin-protocol/src/packet_encoder.rs b/pumpkin-protocol/src/packet_encoder.rs index 1c545804..f970a2eb 100644 --- a/pumpkin-protocol/src/packet_encoder.rs +++ b/pumpkin-protocol/src/packet_encoder.rs @@ -83,10 +83,10 @@ impl PacketEncoder { self.buf .copy_within(start_len..start_len + data_len, start_len + data_prefix_len); - let mut front = &mut self.buf[start_len..]; + let front = &mut self.buf[start_len..]; VarInt(packet_len as i32) - .encode(&mut front) + .encode(front.as_mut()) .map_err(|_| PacketError::EncodeLength)?; // Zero for no compression on this packet. VarInt(0) diff --git a/pumpkin-protocol/src/server/play/s_interact.rs b/pumpkin-protocol/src/server/play/s_interact.rs index a3c31db5..2ad5b496 100644 --- a/pumpkin-protocol/src/server/play/s_interact.rs +++ b/pumpkin-protocol/src/server/play/s_interact.rs @@ -1,4 +1,3 @@ - use num_derive::FromPrimitive; use num_traits::FromPrimitive; use pumpkin_macros::packet; @@ -21,7 +20,7 @@ impl ServerPacket for SInteract { ) -> Result { let entity_id = bytebuf.get_var_int(); let typ = bytebuf.get_var_int(); - let action = ActionType::from_i32(typ.0 as i32).unwrap(); + let action = ActionType::from_i32(typ.0).unwrap(); let target_position: Option<(f32, f32, f32)> = match action { ActionType::Interact => None, ActionType::Attack => None, diff --git a/pumpkin-protocol/src/server/play/s_player_action.rs b/pumpkin-protocol/src/server/play/s_player_action.rs index 4a606116..a217a2b8 100644 --- a/pumpkin-protocol/src/server/play/s_player_action.rs +++ b/pumpkin-protocol/src/server/play/s_player_action.rs @@ -3,6 +3,7 @@ use pumpkin_macros::packet; use crate::{position::WorldPosition, VarInt}; #[derive(serde::Deserialize)] +#[allow(dead_code)] #[packet(0x24)] pub struct SPlayerAction { status: VarInt, diff --git a/pumpkin-protocol/src/server/play/s_player_command.rs b/pumpkin-protocol/src/server/play/s_player_command.rs index e62f9cd0..235baa6d 100644 --- a/pumpkin-protocol/src/server/play/s_player_command.rs +++ b/pumpkin-protocol/src/server/play/s_player_command.rs @@ -1,5 +1,4 @@ use num_derive::FromPrimitive; -use num_traits::FromPrimitive; use pumpkin_macros::packet; use crate::{bytebuf::DeserializerError, ServerPacket, VarInt}; diff --git a/pumpkin-protocol/src/server/play/s_set_creative_slot.rs b/pumpkin-protocol/src/server/play/s_set_creative_slot.rs index 7a2cc4ad..d1a2fbe5 100644 --- a/pumpkin-protocol/src/server/play/s_set_creative_slot.rs +++ b/pumpkin-protocol/src/server/play/s_set_creative_slot.rs @@ -3,6 +3,7 @@ use pumpkin_macros::packet; use crate::slot::Slot; #[derive(serde::Deserialize, Debug)] +#[allow(dead_code)] #[packet(0x32)] pub struct SSetCreativeSlot { slot: i16, diff --git a/pumpkin-protocol/src/slot.rs b/pumpkin-protocol/src/slot.rs index f6b3d837..ffefbc03 100644 --- a/pumpkin-protocol/src/slot.rs +++ b/pumpkin-protocol/src/slot.rs @@ -6,6 +6,7 @@ use serde::{ use crate::VarInt; #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct Slot { item_count: VarInt, item_id: Option, diff --git a/pumpkin-text/src/click.rs b/pumpkin-text/src/click.rs index 83267766..5c959ddf 100644 --- a/pumpkin-text/src/click.rs +++ b/pumpkin-text/src/click.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; #[serde(tag = "action", content = "value", rename_all = "snake_case")] pub enum ClickEvent<'a> { /// Opens a URL - OpenUrl(Cow<'a, str>), + OpenUrl(Cow<'a, str>), /// Works in signs, but only on the root text component RunCommand(Cow<'a, str>), /// Replaces the contents of the chat box with the text, not necessarily a diff --git a/pumpkin-world/src/chunk.rs b/pumpkin-world/src/chunk.rs index 2b07fd2c..23dea869 100644 --- a/pumpkin-world/src/chunk.rs +++ b/pumpkin-world/src/chunk.rs @@ -1,30 +1,3 @@ -// use fastnbt::nbt; - -// pub const BLOCKS_AND_BIOMES: [u8; 2000] = [0x80; 2000]; -// pub const SKY_LIGHT_ARRAYS: [FixedArray; 26] = [FixedArray([0xff; 2048]); 26]; - -// #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -// #[repr(transparent)] -// pub struct FixedArray(pub [T; N]); - -// pub struct TestChunk { -// pub heightmap: Vec, -// } - -// impl Default for TestChunk { -// fn default() -> Self { -// Self::new() -// } -// } - -// impl TestChunk { -// pub fn new() -> Self { -// let bytes = fastnbt::to_bytes(&nbt!({"MOTION_BLOCKING": [L; 123, 256]})).unwrap(); - -// Self { heightmap: bytes } -// } -// } - use std::collections::HashMap; use fastnbt::LongArray; @@ -58,6 +31,7 @@ pub struct ChunkHeightmaps { } #[derive(serde::Deserialize, Debug)] +#[allow(dead_code)] struct ChunkSection { #[serde(rename = "Y")] y: i32, @@ -65,6 +39,7 @@ struct ChunkSection { } #[derive(serde::Deserialize, Debug)] +#[allow(dead_code)] struct ChunkNbt { #[serde(rename = "DataVersion")] data_version: usize, diff --git a/pumpkin-world/src/global_registry.rs b/pumpkin-world/src/global_registry.rs index 57ff7ea1..149e03b8 100644 --- a/pumpkin-world/src/global_registry.rs +++ b/pumpkin-world/src/global_registry.rs @@ -26,6 +26,7 @@ pub fn get_protocol_id(category: &str, entry: &str) -> u32 { .expect("No Entry found") } +#[allow(dead_code)] pub fn get_default<'a>(category: &str) -> Option<&'a str> { REGISTRY .get(category) diff --git a/pumpkin-world/src/item/item_registry.rs b/pumpkin-world/src/item/item_registry.rs index 669501a9..0fa923fc 100644 --- a/pumpkin-world/src/item/item_registry.rs +++ b/pumpkin-world/src/item/item_registry.rs @@ -32,10 +32,12 @@ lazy_static! { serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry."); } +#[allow(dead_code)] pub fn get_item_element(item_id: &str) -> &ItemComponents { &ITEMS.get(item_id).expect("Item not found").components } +#[allow(dead_code)] pub fn get_item_protocol_id(item_id: &str) -> u32 { global_registry::get_protocol_id(ITEM_REGISTRY, item_id) } diff --git a/pumpkin-world/src/world.rs b/pumpkin-world/src/world.rs index 25241341..2d98fc95 100644 --- a/pumpkin-world/src/world.rs +++ b/pumpkin-world/src/world.rs @@ -8,13 +8,11 @@ use flate2::{bufread::ZlibDecoder, read::GzDecoder}; use itertools::Itertools; use rayon::prelude::*; use thiserror::Error; -use tokio::{ - io::{AsyncReadExt, AsyncSeekExt}, - sync::mpsc, -}; +use tokio::sync::mpsc; use crate::chunk::ChunkData; +#[allow(dead_code)] pub struct Level { root_folder: PathBuf, region_folder: PathBuf, diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 02bf7cee..a80e17a4 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -37,11 +37,15 @@ impl Client { self.protocol_version = handshake.protocol_version.0; self.connection_state = handshake.next_state; if self.connection_state == ConnectionState::Login { - if self.protocol_version < CURRENT_MC_PROTOCOL as i32 { - let protocol = self.protocol_version; - self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}")); - } else if self.protocol_version > CURRENT_MC_PROTOCOL as i32 { - self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}")); + let protocol = self.protocol_version; + match protocol.cmp(&(CURRENT_MC_PROTOCOL as i32)) { + std::cmp::Ordering::Less => { + self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}")); + } + std::cmp::Ordering::Equal => {} + std::cmp::Ordering::Greater => { + self.kick(&format!("Server outdated, Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}")); + } } } } diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 297a30c5..f29d21d5 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -5,8 +5,7 @@ use pumpkin_entity::EntityId; use pumpkin_protocol::{ client::play::{ Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, - CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, - CUpdateEntityRot, FilterType, + CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, FilterType, }, position::WorldPosition, server::play::{ @@ -316,7 +315,7 @@ impl Client { } } } - pub fn handle_player_action(&mut self, _server: &mut Server, player_action: SPlayerAction) {} + pub fn handle_player_action(&mut self, _server: &mut Server, _player_action: SPlayerAction) {} pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) { let location = use_item_on.location; diff --git a/pumpkin/src/commands/stop.rs b/pumpkin/src/commands/stop.rs index 8a2fcfc4..852a066b 100644 --- a/pumpkin/src/commands/stop.rs +++ b/pumpkin/src/commands/stop.rs @@ -6,7 +6,7 @@ impl<'a> Command<'a> for StopCommand { const NAME: &'static str = "stop"; 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); } fn player_required() -> bool { diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 81e14730..35c7758b 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use num_derive::{FromPrimitive, ToPrimitive}; -use num_traits::Float; use pumpkin_entity::{entity_type::EntityType, Entity, EntityId}; use pumpkin_inventory::player::PlayerInventory; use pumpkin_protocol::VarInt; diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 308140a0..e4db1387 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::await_holding_refcell_ref)] + use mio::net::TcpListener; use mio::{Events, Interest, Poll, Token}; use std::io::{self}; diff --git a/pumpkin/src/rcon/packet.rs b/pumpkin/src/rcon/packet.rs index e6dd1603..7ed2a91a 100644 --- a/pumpkin/src/rcon/packet.rs +++ b/pumpkin/src/rcon/packet.rs @@ -65,7 +65,7 @@ impl Packet { buf.put_slice(bytes); buf.put_u8(0); buf.put_u8(0); - connection.write(&buf).unwrap(); + let _ = connection.write(&buf).unwrap(); Ok(()) }