using Content.Shared.Input;
using Content.Shared.Inventory;
using Content.Shared.Popups;
+using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Whitelist;
_hands.TryDrop(uid, hands.ActiveHand, handsComp: hands);
_storage.Insert(slotItem, handItem.Value, out var stacked, out _);
- if (stacked != null)
- _hands.TryPickup(uid, stacked.Value, handsComp: hands);
+ // if the hand item stacked with the things in inventory, but there's no more space left for the rest
+ // of the stack, place the stack back in hand rather than dropping it on the floor
+ if (stacked != null && !_storage.CanInsert(slotItem, handItem.Value, out _))
+ {
+ if (TryComp<StackComponent>(handItem.Value, out var handStack) && handStack.Count > 0)
+ _hands.TryPickup(uid, handItem.Value, handsComp: hands);
+ }
return;
}