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

Differentiate between single and stack drops #559

Merged
merged 2 commits into from
Feb 18, 2025
Merged
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
10 changes: 7 additions & 3 deletions pumpkin/src/entity/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,19 +980,23 @@ impl Player {
.await;
}

pub async fn drop_item(&self, server: &Server) {
pub async fn drop_item(&self, server: &Server, drop_stack: bool) {
let mut inv = self.inventory.lock().await;
if let Some(item) = inv.held_item_mut() {
let drop_amount = if drop_stack { item.item_count } else { 1 };
let entity = server.add_entity(
self.living_entity.entity.pos.load(),
EntityType::ITEM,
&self.world().await,
);
let item_entity = Arc::new(ItemEntity::new(entity, &item.clone()));
let item_entity = Arc::new(ItemEntity::new(
entity,
&ItemStack::new(drop_amount, item.item),
));
self.world().await.spawn_entity(item_entity.clone()).await;
item_entity.send_meta_packet().await;
// decrase item in hotbar
inv.decrease_current_stack(1);
inv.decrease_current_stack(drop_amount);
}
}

Expand Down
7 changes: 5 additions & 2 deletions pumpkin/src/net/packet/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,11 @@ impl Player {
}
self.update_sequence(player_action.sequence.0);
}
Status::DropItemStack | Status::DropItem => {
self.drop_item(server).await;
Status::DropItem => {
self.drop_item(server, false).await;
}
Status::DropItemStack => {
self.drop_item(server, true).await;
}
Status::ShootArrowOrFinishEating | Status::SwapItem => {
log::debug!("todo");
Expand Down