Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dropping items #450

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions pumpkin/src/net/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::server::Server;
use pumpkin_core::text::TextComponent;
use pumpkin_core::GameMode;
use pumpkin_inventory::container_click::{
Click, ClickType, KeyClick, MouseClick, MouseDragState, MouseDragType,
Click, ClickType, KeyClick, MouseClick, MouseDragState, MouseDragType, DropType,
};
use pumpkin_inventory::drag_handler::DragHandler;
use pumpkin_inventory::window_property::{WindowProperty, WindowPropertyTrait};
Expand Down Expand Up @@ -272,9 +272,9 @@ impl Player {
self.mouse_drag(drag_handler, opened_container, drag_state)
.await
}
ClickType::DropType(_drop_type) => {
log::debug!("todo");
Ok(())
ClickType::DropType(drop_type) => {
self.handle_drop_item(opened_container, drop_type, click.slot)
.await
}
}
}
Expand Down Expand Up @@ -469,6 +469,38 @@ impl Player {
}
}

async fn handle_drop_item(
&self,
opened_container: Option<&mut Box<dyn Container>>,
drop_type: DropType,
slot: container_click::Slot,
) -> Result<(), InventoryError> {
let mut inventory = self.inventory().lock().await;
let mut container = OptionallyCombinedContainer::new(&mut inventory, opened_container);
match slot {
container_click::Slot::Normal(slot) => {
let mut carried_item = self.carried_item.load();
let res = match drop_type {
DropType::SingleItem => container.handle_item_change(
&mut carried_item,
slot,
MouseClick::Right,
false,
),
DropType::FullStack => container.handle_item_change(
&mut carried_item,
slot,
MouseClick::Left,
false,
),
};
self.carried_item.store(carried_item);
res
}
container_click::Slot::OutsideInventory => Ok(()),
}
}

async fn get_current_players_in_container(&self, server: &Server) -> Vec<Arc<Self>> {
let player_ids: Vec<i32> = {
let open_containers = server.open_containers.read().await;
Expand Down
Loading
Loading