Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet committed Sep 22, 2024
1 parent 1b5042a commit 4f4c723
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
15 changes: 4 additions & 11 deletions pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::entity::item::ItemEntity;
use crate::entity::player::Player;
use crate::server::Server;
use itertools::Itertools;
Expand Down Expand Up @@ -183,12 +182,7 @@ impl Player {
container_click::Slot::Normal(slot) => slot,
container_click::Slot::OutsideInventory => Err(InventoryError::InvalidPacket)?,
};
self.drop_items(
opened_container.as_deref_mut(),
slot,
drop_type,
server.clone(),
)?;
self.drop_items(opened_container.as_deref_mut(), slot, drop_type)?;
Ok(())
}
}?;
Expand All @@ -211,8 +205,8 @@ impl Player {
Ok(())
}

pub fn send_single_slot_inventory_change(&self, server: &Arc<Server>, slot_index: usize) {
let mut inventory = self.inventory.lock();
pub fn send_single_slot_inventory_change(&self, slot_index: usize) {
let inventory = self.inventory.lock();
let state_id = inventory
.state_id
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
Expand Down Expand Up @@ -408,7 +402,6 @@ impl Player {
opened_container: Option<&mut Box<dyn Container>>,
slot: usize,
drop_type: DropType,
server: Arc<Server>,
) -> Result<(), InventoryError> {
let mut inventory = self.inventory.lock();
let mut container = OptionallyCombinedContainer::new(&mut inventory, opened_container);
Expand All @@ -419,7 +412,7 @@ impl Player {
let Some(item) = slot else {
return Ok(());
};
let dropped_item = match drop_type {
match drop_type {
DropType::FullStack => {
let dropped_item = *item;
**slot = None;
Expand Down
8 changes: 4 additions & 4 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl Player {
let mut inventory = self.inventory.lock();
let slot = inventory.held_item_mut();
if let Some(item) = slot {
ItemEntity::new(&self.entity, *item, server.clone());
ItemEntity::spawn(&self.entity, *item, server.clone());
*slot = None;
}
}
Expand All @@ -496,9 +496,9 @@ impl Player {
held_item.item_count -= 1;
let mut item = *held_item;
item.item_count = 1;
ItemEntity::new(&self.entity, item, server.clone());
ItemEntity::spawn(&self.entity, item, server.clone());
} else {
ItemEntity::new(&self.entity, *held_item, server.clone());
ItemEntity::spawn(&self.entity, *held_item, server.clone());
*slot = None;
}
}
Expand Down Expand Up @@ -581,7 +581,7 @@ impl Player {
let item = None;
self.carried_item.swap(item);
if let Some(item) = item {
ItemEntity::new(&self.entity, item, server.clone());
ItemEntity::spawn(&self.entity, item, server.clone());
}
Ok(())
}
Expand Down
9 changes: 2 additions & 7 deletions pumpkin/src/entity/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use crate::entity::player::Player;
use crate::entity::{random_float, Entity};
use crate::server::Server;
use crossbeam::atomic::AtomicCell;
use itertools::Itertools;
use num_traits::float::FloatCore;
use num_traits::real::Real;
use pumpkin_core::math::vector3::Vector3;
use pumpkin_entity::entity_type::EntityType;
use pumpkin_entity::pose::EntityPose;
Expand All @@ -15,7 +12,6 @@ use pumpkin_protocol::client::play::{
};
use pumpkin_protocol::slot::Slot;
use pumpkin_world::item::ItemStack;
use rand::Rng;
use rayon::prelude::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
Expand All @@ -29,7 +25,7 @@ pub struct ItemEntity {
}

impl ItemEntity {
pub fn new(player_entity: &Entity, item_stack: ItemStack, server: Arc<Server>) {
pub fn spawn(player_entity: &Entity, item_stack: ItemStack, server: Arc<Server>) {
let is_able_to_be_picked_up = Arc::new(AtomicBool::new(false));
{
let is_able_to_be_picked_up = is_able_to_be_picked_up.clone();
Expand Down Expand Up @@ -84,7 +80,7 @@ impl ItemEntity {
});
}

pub fn check_pickup(self) -> PickupEvent {
pub(self) fn check_pickup(self) -> PickupEvent {
if !self.is_able_to_be_picked_up.load(Ordering::Relaxed) {
return PickupEvent::NotPickedUp(self);
}
Expand Down Expand Up @@ -193,7 +189,6 @@ async fn drop_loop(item_entity: ItemEntity, server: Arc<Server>) {
}
drop(inventory);
player.send_single_slot_inventory_change(
&server,
index.expect("It needs to have a valid slot for this path to get loaded"),
);
break;
Expand Down
18 changes: 8 additions & 10 deletions pumpkin/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ use pumpkin_protocol::{
};
use pumpkin_world::chunk::ChunkData;
use pumpkin_world::coordinates::ChunkRelativeBlockCoordinates;
use pumpkin_world::level::WorldError;
use rand::Rng;
use std::ops::Mul;
use std::sync::atomic::Ordering;
use std::sync::{atomic::AtomicBool, Arc};
use tokio::sync::mpsc::{Receiver, Sender};
use uuid::Uuid;

mod direction;
Expand Down Expand Up @@ -170,7 +168,7 @@ impl Entity {
return;
}
let mut old_pos = self.pos.load();
let mut pos = old_pos.add(&velocity);
let pos = old_pos.add(&velocity);
let chunk_pos = Vector2::new(
get_section_cord(pos.x as i32),
get_section_cord(pos.z as i32),
Expand All @@ -188,14 +186,13 @@ impl Entity {
// TODO: Add check for other blocks that affect collision, like water
if block_id.is_air() {
return;
} else {
old_pos.y = pos.y.ceil();
self.pos.store(old_pos);
let mut velocity = self.velocity.load();
velocity.y = velocity.y.min(0.);

self.on_ground.store(true, Ordering::Relaxed);
}
old_pos.y = pos.y.ceil();
self.pos.store(old_pos);
let mut velocity = self.velocity.load();
velocity.y = velocity.y.min(0.);

self.on_ground.store(true, Ordering::Relaxed);
}
}

Expand Down Expand Up @@ -265,6 +262,7 @@ impl Entity {
self.velocity.store(velocity);
}

#[allow(clippy::type_complexity)]
fn get_all_collisions(
&self,
neighbours: Vec<((i32, i32), Vector3<f64>)>,
Expand Down

0 comments on commit 4f4c723

Please sign in to comment.