Fix: all clippy warns

This commit is contained in:
Alexander Medvedev 2024-08-19 20:08:02 +01:00
parent a6d9ed216d
commit de7b3aa2ea
21 changed files with 35 additions and 53 deletions

View File

@ -1,5 +1,6 @@
use pumpkin_world::item::Item; use pumpkin_world::item::Item;
#[allow(dead_code)]
pub struct PlayerInventory { pub struct PlayerInventory {
// Main Inventory + Hotbar // Main Inventory + Hotbar
items: [Option<Item>; 36], items: [Option<Item>; 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) { pub fn set_selected(&mut self, slot: i16) {
assert!((0..9).contains(&slot)); assert!((0..9).contains(&slot));

View File

@ -1,7 +1,6 @@
use pumpkin_macros::packet; use pumpkin_macros::packet;
use serde::Serialize; use serde::Serialize;
#[derive(Serialize)] #[derive(Serialize)]
#[packet(0x01)] #[packet(0x01)]
pub struct CPluginMessage<'a> { pub struct CPluginMessage<'a> {

View File

@ -32,7 +32,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
data_buf.put_i16(block_count); data_buf.put_i16(block_count);
//// Block states //// 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 dynamic block_size work
// TODO: make direct block_size work // TODO: make direct block_size work
enum PaletteType { enum PaletteType {
@ -63,7 +63,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
palette.iter().enumerate().for_each(|(i, id)| { palette.iter().enumerate().for_each(|(i, id)| {
palette_map.insert(*id, i); palette_map.insert(*id, i);
// Palette // 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) { for block_clump in chunk.chunks(64 / block_size as usize) {
let mut out_long: i64 = 0; let mut out_long: i64 = 0;
@ -109,7 +109,7 @@ impl<'a> ClientPacket for CChunkData<'a> {
// Size // Size
buf.put_var_int(&VarInt(data_buf.buf().len() as i32)); buf.put_var_int(&VarInt(data_buf.buf().len() as i32));
// Data // Data
buf.put_slice(&data_buf.buf()); buf.put_slice(data_buf.buf());
// TODO: block entities // TODO: block entities
buf.put_var_int(&VarInt(0)); buf.put_var_int(&VarInt(0));

View File

@ -21,6 +21,7 @@ pub struct CParticle<'a> {
} }
impl<'a> CParticle<'a> { impl<'a> CParticle<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
long_distance: bool, long_distance: bool,
x: f64, x: f64,

View File

@ -83,10 +83,10 @@ impl PacketEncoder {
self.buf self.buf
.copy_within(start_len..start_len + data_len, start_len + data_prefix_len); .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) VarInt(packet_len as i32)
.encode(&mut front) .encode(front.as_mut())
.map_err(|_| PacketError::EncodeLength)?; .map_err(|_| PacketError::EncodeLength)?;
// Zero for no compression on this packet. // Zero for no compression on this packet.
VarInt(0) VarInt(0)

View File

@ -1,4 +1,3 @@
use num_derive::FromPrimitive; use num_derive::FromPrimitive;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use pumpkin_macros::packet; use pumpkin_macros::packet;
@ -21,7 +20,7 @@ impl ServerPacket for SInteract {
) -> Result<Self, crate::bytebuf::DeserializerError> { ) -> Result<Self, crate::bytebuf::DeserializerError> {
let entity_id = bytebuf.get_var_int(); let entity_id = bytebuf.get_var_int();
let typ = 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 { let target_position: Option<(f32, f32, f32)> = match action {
ActionType::Interact => None, ActionType::Interact => None,
ActionType::Attack => None, ActionType::Attack => None,

View File

@ -3,6 +3,7 @@ use pumpkin_macros::packet;
use crate::{position::WorldPosition, VarInt}; use crate::{position::WorldPosition, VarInt};
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
#[allow(dead_code)]
#[packet(0x24)] #[packet(0x24)]
pub struct SPlayerAction { pub struct SPlayerAction {
status: VarInt, status: VarInt,

View File

@ -1,5 +1,4 @@
use num_derive::FromPrimitive; use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use pumpkin_macros::packet; use pumpkin_macros::packet;
use crate::{bytebuf::DeserializerError, ServerPacket, VarInt}; use crate::{bytebuf::DeserializerError, ServerPacket, VarInt};

View File

@ -3,6 +3,7 @@ use pumpkin_macros::packet;
use crate::slot::Slot; use crate::slot::Slot;
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
#[packet(0x32)] #[packet(0x32)]
pub struct SSetCreativeSlot { pub struct SSetCreativeSlot {
slot: i16, slot: i16,

View File

@ -6,6 +6,7 @@ use serde::{
use crate::VarInt; use crate::VarInt;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Slot { pub struct Slot {
item_count: VarInt, item_count: VarInt,
item_id: Option<VarInt>, item_id: Option<VarInt>,

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "action", content = "value", rename_all = "snake_case")] #[serde(tag = "action", content = "value", rename_all = "snake_case")]
pub enum ClickEvent<'a> { pub enum ClickEvent<'a> {
/// Opens a URL /// Opens a URL
OpenUrl(Cow<'a, str>), OpenUrl(Cow<'a, str>),
/// Works in signs, but only on the root text component /// Works in signs, but only on the root text component
RunCommand(Cow<'a, str>), RunCommand(Cow<'a, str>),
/// Replaces the contents of the chat box with the text, not necessarily a /// Replaces the contents of the chat box with the text, not necessarily a

View File

@ -1,30 +1,3 @@
// use fastnbt::nbt;
// pub const BLOCKS_AND_BIOMES: [u8; 2000] = [0x80; 2000];
// pub const SKY_LIGHT_ARRAYS: [FixedArray<u8, 2048>; 26] = [FixedArray([0xff; 2048]); 26];
// #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
// #[repr(transparent)]
// pub struct FixedArray<T, const N: usize>(pub [T; N]);
// pub struct TestChunk {
// pub heightmap: Vec<u8>,
// }
// 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 std::collections::HashMap;
use fastnbt::LongArray; use fastnbt::LongArray;
@ -58,6 +31,7 @@ pub struct ChunkHeightmaps {
} }
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ChunkSection { struct ChunkSection {
#[serde(rename = "Y")] #[serde(rename = "Y")]
y: i32, y: i32,
@ -65,6 +39,7 @@ struct ChunkSection {
} }
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
#[allow(dead_code)]
struct ChunkNbt { struct ChunkNbt {
#[serde(rename = "DataVersion")] #[serde(rename = "DataVersion")]
data_version: usize, data_version: usize,

View File

@ -26,6 +26,7 @@ pub fn get_protocol_id(category: &str, entry: &str) -> u32 {
.expect("No Entry found") .expect("No Entry found")
} }
#[allow(dead_code)]
pub fn get_default<'a>(category: &str) -> Option<&'a str> { pub fn get_default<'a>(category: &str) -> Option<&'a str> {
REGISTRY REGISTRY
.get(category) .get(category)

View File

@ -32,10 +32,12 @@ lazy_static! {
serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry."); 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 { pub fn get_item_element(item_id: &str) -> &ItemComponents {
&ITEMS.get(item_id).expect("Item not found").components &ITEMS.get(item_id).expect("Item not found").components
} }
#[allow(dead_code)]
pub fn get_item_protocol_id(item_id: &str) -> u32 { pub fn get_item_protocol_id(item_id: &str) -> u32 {
global_registry::get_protocol_id(ITEM_REGISTRY, item_id) global_registry::get_protocol_id(ITEM_REGISTRY, item_id)
} }

View File

@ -8,13 +8,11 @@ use flate2::{bufread::ZlibDecoder, read::GzDecoder};
use itertools::Itertools; use itertools::Itertools;
use rayon::prelude::*; use rayon::prelude::*;
use thiserror::Error; use thiserror::Error;
use tokio::{ use tokio::sync::mpsc;
io::{AsyncReadExt, AsyncSeekExt},
sync::mpsc,
};
use crate::chunk::ChunkData; use crate::chunk::ChunkData;
#[allow(dead_code)]
pub struct Level { pub struct Level {
root_folder: PathBuf, root_folder: PathBuf,
region_folder: PathBuf, region_folder: PathBuf,

View File

@ -37,11 +37,15 @@ impl Client {
self.protocol_version = handshake.protocol_version.0; self.protocol_version = handshake.protocol_version.0;
self.connection_state = handshake.next_state; self.connection_state = handshake.next_state;
if self.connection_state == ConnectionState::Login { if self.connection_state == ConnectionState::Login {
if self.protocol_version < CURRENT_MC_PROTOCOL as i32 { let protocol = self.protocol_version;
let protocol = self.protocol_version; match protocol.cmp(&(CURRENT_MC_PROTOCOL as i32)) {
self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}")); std::cmp::Ordering::Less => {
} else if self.protocol_version > CURRENT_MC_PROTOCOL as i32 { self.kick(&format!("Client outdated ({protocol}), Server uses Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL}"));
self.kick(&format!("Server outdated, 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}"));
}
} }
} }
} }

View File

@ -5,8 +5,7 @@ use pumpkin_entity::EntityId;
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, Animation, CBlockUpdate, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation,
CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, FilterType,
CUpdateEntityRot, FilterType,
}, },
position::WorldPosition, position::WorldPosition,
server::play::{ 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) { pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) {
let location = use_item_on.location; let location = use_item_on.location;

View File

@ -6,7 +6,7 @@ impl<'a> Command<'a> for StopCommand {
const NAME: &'static str = "stop"; const NAME: &'static str = "stop";
const DESCRIPTION: &'static str = "Stops the server"; 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); std::process::exit(0);
} }
fn player_required() -> bool { fn player_required() -> bool {

View File

@ -1,7 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use num_derive::{FromPrimitive, ToPrimitive}; use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::Float;
use pumpkin_entity::{entity_type::EntityType, Entity, EntityId}; use pumpkin_entity::{entity_type::EntityType, Entity, EntityId};
use pumpkin_inventory::player::PlayerInventory; use pumpkin_inventory::player::PlayerInventory;
use pumpkin_protocol::VarInt; use pumpkin_protocol::VarInt;

View File

@ -1,3 +1,5 @@
#![allow(clippy::await_holding_refcell_ref)]
use mio::net::TcpListener; use mio::net::TcpListener;
use mio::{Events, Interest, Poll, Token}; use mio::{Events, Interest, Poll, Token};
use std::io::{self}; use std::io::{self};

View File

@ -65,7 +65,7 @@ impl Packet {
buf.put_slice(bytes); buf.put_slice(bytes);
buf.put_u8(0); buf.put_u8(0);
buf.put_u8(0); buf.put_u8(0);
connection.write(&buf).unwrap(); let _ = connection.write(&buf).unwrap();
Ok(()) Ok(())
} }