From 2f99d76aaad022e65550c88594b7b9b259503c16 Mon Sep 17 00:00:00 2001 From: UnrealCodec <43702198+FussballAndy@users.noreply.github.com> Date: Fri, 17 Jun 2022 21:18:54 +0200 Subject: [PATCH] Apply 1.60 clippy lints and apply variable name (#544) * FIx clippy 1.60 lints * cargo fmt --- feather/base/src/anvil/player.rs | 19 +++++++++---------- feather/worldgen/src/lib.rs | 6 +++--- libcraft/items/src/item_stack.rs | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/feather/base/src/anvil/player.rs b/feather/base/src/anvil/player.rs index 2e6100eda..c6389e82d 100644 --- a/feather/base/src/anvil/player.rs +++ b/feather/base/src/anvil/player.rs @@ -71,18 +71,17 @@ pub struct InventorySlot { impl InventorySlot { /// Converts an [`ItemStack`] and network protocol index into an [`InventorySlot`]. - pub fn from_network_index(network: usize, stack: &ItemStack) -> Option { - let slot = if SLOT_HOTBAR_OFFSET <= network && network < SLOT_HOTBAR_OFFSET + HOTBAR_SIZE { + #[allow(clippy::manual_range_contains)] + pub fn from_network_index(index: usize, stack: &ItemStack) -> Option { + let slot = if SLOT_HOTBAR_OFFSET <= index && index < SLOT_HOTBAR_OFFSET + HOTBAR_SIZE { // Hotbar - (network - SLOT_HOTBAR_OFFSET) as i8 - } else if network == SLOT_OFFHAND { + (index - SLOT_HOTBAR_OFFSET) as i8 + } else if index == SLOT_OFFHAND { -106 - } else if SLOT_ARMOR_MIN <= network && network <= SLOT_ARMOR_MAX { - ((SLOT_ARMOR_MAX - network) + 100) as i8 - } else if SLOT_INVENTORY_OFFSET <= network - && network < SLOT_INVENTORY_OFFSET + INVENTORY_SIZE - { - network as i8 + } else if SLOT_ARMOR_MIN <= index && index <= SLOT_ARMOR_MAX { + ((SLOT_ARMOR_MAX - index) + 100) as i8 + } else if SLOT_INVENTORY_OFFSET <= index && index < SLOT_INVENTORY_OFFSET + INVENTORY_SIZE { + index as i8 } else { return None; }; diff --git a/feather/worldgen/src/lib.rs b/feather/worldgen/src/lib.rs index 2e55c7ae7..36a421ee5 100644 --- a/feather/worldgen/src/lib.rs +++ b/feather/worldgen/src/lib.rs @@ -340,9 +340,9 @@ impl NearbyBiomes { let chunk_x = (x / 16) as usize; let chunk_z = (z / 16) as usize; - let mut local_x = (ox % 16).abs() as usize; - let local_y = (oy % 16).abs() as usize; - let mut local_z = (oz % 16).abs() as usize; + let mut local_x = (ox % 16).unsigned_abs(); + let local_y = (oy % 16).unsigned_abs(); + let mut local_z = (oz % 16).unsigned_abs(); if ox < 0 { local_x = 16 - local_x; diff --git a/libcraft/items/src/item_stack.rs b/libcraft/items/src/item_stack.rs index 067e0ac16..410e6650d 100644 --- a/libcraft/items/src/item_stack.rs +++ b/libcraft/items/src/item_stack.rs @@ -366,7 +366,7 @@ pub enum ItemStackError { impl Display for ItemStackError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) + write!(f, "{:?}", self) } }