diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 1caf6d488cfb91..2c58ac45be2dcf 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -621,6 +621,29 @@ public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? s return true; } + private bool CanCombineStacks( + ServerStorageComponent storageComp, + StackComponent stack) + { + if (storageComp.Storage == null) + return false; + + var stackQuery = GetEntityQuery(); + var countLeft = stack.Count; + foreach (var ent in storageComp.Storage.ContainedEntities) + { + if (!stackQuery.TryGetComponent(ent, out var destStack)) + continue; + + if (destStack.StackTypeId != stack.StackTypeId) + continue; + + countLeft -= _stack.GetAvailableSpace(stack); + } + + return countLeft <= 0; + } + // REMOVE: remove and drop on the ground public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null) {