From 45df595c1513bed2c31209101afc7574ded29cfe Mon Sep 17 00:00:00 2001 From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:24:13 -0700 Subject: [PATCH] Fix storage fill giving no reason for failing (#27122) --- .../EntitySystems/StorageSystem.Fill.cs | 11 ++++++++++ .../EntitySystems/SharedStorageSystem.cs | 21 ++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs index 10278cc805..768491f987 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs @@ -65,12 +65,23 @@ public sealed partial class StorageSystem var sortedItems = items .OrderByDescending(x => ItemSystem.GetItemShape(x.Comp).GetArea()); + ClearCantFillReasons(); foreach (var ent in sortedItems) { if (Insert(uid, ent, out _, out var reason, storageComp: storage, playSound: false)) continue; + if (CantFillReasons.Count > 0) + { + var reasons = string.Join(", ", CantFillReasons.Select(s => Loc.GetString(s))); + if (reason == null) + reason = reasons; + else + reason += $", {reasons}"; + } + Log.Error($"Tried to StorageFill {ToPrettyString(ent)} inside {ToPrettyString(uid)} but can't. reason: {reason}"); + ClearCantFillReasons(); Del(ent); } } diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 9d364dded0..194ea985fb 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -3,7 +3,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.ActionBlocker; using Content.Shared.Containers.ItemSlots; -using Content.Shared.Coordinates; using Content.Shared.Destructible; using Content.Shared.DoAfter; using Content.Shared.Hands.Components; @@ -65,6 +64,8 @@ public abstract class SharedStorageSystem : EntitySystem private readonly List _sortedSizes = new(); private FrozenDictionary _nextSmallest = FrozenDictionary.Empty; + protected readonly List CantFillReasons = []; + /// public override void Initialize() { @@ -628,8 +629,15 @@ public abstract class SharedStorageSystem : EntitySystem if (CheckingCanInsert) return; - if (!CanInsert(uid, args.EntityUid, out _, component, ignoreStacks: true)) + if (!CanInsert(uid, args.EntityUid, out var reason, component, ignoreStacks: true)) + { +#if DEBUG + if (reason != null) + CantFillReasons.Add(reason); +#endif + args.Cancel(); + } } public void UpdateAppearance(Entity entity) @@ -1072,7 +1080,7 @@ public abstract class SharedStorageSystem : EntitySystem for (int i = 0; i < list.Count; i++) { var saved = list[i]; - + if (saved == location) { list.Remove(location); @@ -1259,6 +1267,13 @@ public abstract class SharedStorageSystem : EntitySystem } } + protected void ClearCantFillReasons() + { +#if DEBUG + CantFillReasons.Clear(); +#endif + } + /// /// Plays a clientside pickup animation for the specified uid. /// -- 2.52.0