Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix bugs in implementation of handle_single_click
  • Loading branch information
caelunshun committed May 11, 2020
commit 9fb3dac045c0c60193a51a4e501ded63cda16aa2
23 changes: 18 additions & 5 deletions server/player/src/packet_handlers/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,24 @@ fn handle_single_click(
}
} else {
// Pick up the item in the slot
let mut inv = world.get_mut::<Inventory>(player);
let _ = inv.clear_item_at(packet.slot as SlotIndex);
if let Some(item) = inv.item_at(packet.slot as SlotIndex).flatten() {
drop(inv);
world.add(player, PickedItem(item)).unwrap();
let picked_up = world
.get::<Inventory>(player)
.item_at(packet.slot as SlotIndex)
.flatten();
let mut count = picked_up.map(|item| item.amount).unwrap_or(0);
if button == MouseButton::Right {
count = (count + 1) / 2;
}
if let Some(item) = picked_up {
world
.add(player, PickedItem(ItemStack::new(item.ty, count)))
.unwrap();

let mut inv = world.get_mut::<Inventory>(player);
inv.set_item_at(
packet.slot as SlotIndex,
ItemStack::new(item.ty, item.amount - count),
)
}
}

Expand Down