chore: clippy enforce unwrap_used, expect_used and panic
release is not far
This commit is contained in:
1 parent
0eb7b936db
commit
49360e53ef
291 files changed
+3200
-1783
No files matched your search
@@ -90,7 +90,10 @@ async fn recipe_matches(
|
||||
result,
|
||||
..
|
||||
}) => {
|
||||
if pattern.len() != input_height || pattern.first().unwrap().len() != input_width {
|
||||
#[allow(clippy::redundant_closure_for_method_calls)]
|
||||
if pattern.len() != input_height
|
||||
|| pattern.first().map_or(0, |f| f.len()) != input_width
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -120,10 +123,13 @@ async fn recipe_matches(
|
||||
continue;
|
||||
}
|
||||
|
||||
let ingredient = key
|
||||
let Some(ingredient) = key
|
||||
.iter()
|
||||
.find_map(|(k, v)| (*k == current_key).then_some(v))
|
||||
.expect("Crafting recipe used invalid key");
|
||||
else {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
};
|
||||
|
||||
if !ingredient.match_item(slot.item) {
|
||||
matched = false;
|
||||
@@ -136,7 +142,10 @@ async fn recipe_matches(
|
||||
matched = true;
|
||||
'outer: for y in 0..pattern.len() {
|
||||
for x in 0..pattern[y].len() {
|
||||
let current_key = pattern[y].chars().nth(x).unwrap();
|
||||
let Some(current_key) = pattern[y].chars().nth(x) else {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
};
|
||||
let slot = inventory
|
||||
.get_stack(
|
||||
(y + y_offset) * inventory.get_height()
|
||||
@@ -150,10 +159,13 @@ async fn recipe_matches(
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let ingredient = key
|
||||
let Some(ingredient) = key
|
||||
.iter()
|
||||
.find_map(|(k, v)| (*k == current_key).then_some(v))
|
||||
.expect("Crafting recipe used invalid key");
|
||||
else {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
};
|
||||
if !ingredient.match_item(slot.item) {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
@@ -242,7 +254,10 @@ async fn recipe_matches(
|
||||
result,
|
||||
..
|
||||
}) => {
|
||||
if pattern.len() != input_height || pattern.first().unwrap().len() != input_width {
|
||||
#[allow(clippy::redundant_closure_for_method_calls)]
|
||||
if pattern.len() != input_height
|
||||
|| pattern.first().map_or(0, |f| f.len()) != input_width
|
||||
{
|
||||
return None;
|
||||
}
|
||||
if count
|
||||
@@ -268,11 +283,12 @@ async fn recipe_matches(
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let ingredient = key
|
||||
.iter()
|
||||
.find(|(k, _)| *k == current_key)
|
||||
.map(|(_, v)| v)
|
||||
.expect("Crafting recipe used invalid key");
|
||||
let Some(ingredient) =
|
||||
key.iter().find(|(k, _)| *k == current_key).map(|(_, v)| v)
|
||||
else {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
};
|
||||
if !ingredient.match_item(slot.item) {
|
||||
matched = false;
|
||||
break 'outer;
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
//! - [`SyncHandler`] - Synchronizes inventory state between server and client
|
||||
//!
|
||||
//! # Module Structure
|
||||
|
||||
#![deny(clippy::unwrap_used)]
|
||||
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
|
||||
//!
|
||||
//! - [`player`] - Player inventory and screen handler implementations
|
||||
//! - [`crafting`] - Crafting table and inventory crafting mechanics
|
||||
|
||||
@@ -116,7 +116,9 @@ impl PlayerInventory {
|
||||
match hand {
|
||||
Hand::Right => self.set_held_item(stack).await,
|
||||
Hand::Left => {
|
||||
let slot = self.equipment_slots.get(&Self::OFF_HAND_SLOT).unwrap();
|
||||
let Some(slot) = self.equipment_slots.get(&Self::OFF_HAND_SLOT) else {
|
||||
return;
|
||||
};
|
||||
self.entity_equipment.lock().await.put(slot, stack);
|
||||
}
|
||||
}
|
||||
@@ -137,7 +139,9 @@ impl PlayerInventory {
|
||||
///
|
||||
/// Mojang name: `getOffHandStack`
|
||||
pub async fn off_hand_item(&self) -> ItemStack {
|
||||
let slot = self.equipment_slots.get(&Self::OFF_HAND_SLOT).unwrap();
|
||||
let Some(slot) = self.equipment_slots.get(&Self::OFF_HAND_SLOT) else {
|
||||
return ItemStack::EMPTY.clone();
|
||||
};
|
||||
self.entity_equipment.lock().await.get(slot)
|
||||
}
|
||||
|
||||
@@ -146,7 +150,9 @@ impl PlayerInventory {
|
||||
/// # Returns
|
||||
/// The new main hand item and new off-hand item.
|
||||
pub async fn swap_item(&self) -> (ItemStack, ItemStack) {
|
||||
let slot = self.equipment_slots.get(&Self::OFF_HAND_SLOT).unwrap();
|
||||
let Some(slot) = self.equipment_slots.get(&Self::OFF_HAND_SLOT) else {
|
||||
return (ItemStack::EMPTY.clone(), ItemStack::EMPTY.clone());
|
||||
};
|
||||
let mut equipment = self.entity_equipment.lock().await;
|
||||
let selected = self.get_selected_slot() as usize;
|
||||
let mut main_inv = self.main_inventory.write().await;
|
||||
@@ -514,8 +520,6 @@ impl PlayerInventory {
|
||||
pub fn set_selected_slot(&self, slot: u8) {
|
||||
if Self::is_valid_hotbar_index(slot as usize) {
|
||||
self.selected_slot.store(slot, Ordering::Relaxed);
|
||||
} else {
|
||||
panic!("Invalid hotbar slot: {slot}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -917,15 +917,14 @@ pub trait ScreenHandler: Send + Sync {
|
||||
if (stack.are_items_and_components_equal(&cursor_stack) || stack.is_empty())
|
||||
&& slot.can_insert(&cursor_stack).await
|
||||
{
|
||||
let mut inserting_count = if drag_button == 0 {
|
||||
initial_count / behaviour.drag_slots.len() as u8
|
||||
} else if drag_button == 1 {
|
||||
1
|
||||
} else if drag_button == 2 {
|
||||
cursor_stack.item_count = cursor_stack.get_max_stack_size();
|
||||
cursor_stack.item_count
|
||||
} else {
|
||||
panic!("Invalid drag button: {drag_button}");
|
||||
let mut inserting_count = match drag_button {
|
||||
0 => initial_count / behaviour.drag_slots.len() as u8,
|
||||
1 => 1,
|
||||
2 => {
|
||||
cursor_stack.item_count = cursor_stack.get_max_stack_size();
|
||||
cursor_stack.item_count
|
||||
}
|
||||
_ => 0,
|
||||
};
|
||||
inserting_count = inserting_count
|
||||
.min(max(
|
||||
|
||||
@@ -70,8 +70,7 @@ impl StonecutterScreenHandler {
|
||||
|
||||
if recipe_index != u8::MAX && (recipe_index as usize) < available_recipes.len() {
|
||||
let recipe = available_recipes[recipe_index as usize];
|
||||
let item =
|
||||
Item::from_registry_key(recipe.result.id).expect("Invalid recipe result item");
|
||||
let item = Item::from_registry_key(recipe.result.id).unwrap_or(&Item::AIR);
|
||||
let result = ItemStack::new(recipe.result.count, item);
|
||||
self.output_inventory.set_stack(0, result).await;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user