diff --git a/Content.Shared/Foldable/FoldableSystem.cs b/Content.Shared/Foldable/FoldableSystem.cs index 73916f1c15..63ef376d5f 100644 --- a/Content.Shared/Foldable/FoldableSystem.cs +++ b/Content.Shared/Foldable/FoldableSystem.cs @@ -30,6 +30,7 @@ public sealed class FoldableSystem : EntitySystem SubscribeLocalEvent(OnFoldableInit); SubscribeLocalEvent(OnInsertEvent); SubscribeLocalEvent(OnFoldableOpenAttempt); + SubscribeLocalEvent(OnEntityStorageAttemptInsert); SubscribeLocalEvent(OnStrapAttempt); } @@ -56,6 +57,13 @@ public sealed class FoldableSystem : EntitySystem args.Cancelled = true; } + private void OnEntityStorageAttemptInsert(Entity entity, + ref EntityStorageInsertedIntoAttemptEvent args) + { + if (entity.Comp.IsFolded) + args.Cancelled = true; + } + /// /// Returns false if the entity isn't foldable. /// diff --git a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs index 06b1c15f2e..a0d4e418cc 100644 --- a/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs +++ b/Content.Shared/Storage/Components/SharedEntityStorageComponent.cs @@ -146,9 +146,18 @@ public sealed class EntityStorageComponentState : ComponentState } } +/// +/// Raised on the entity being inserted whenever checking if an entity can be inserted into an entity storage. +/// [ByRefEvent] public record struct InsertIntoEntityStorageAttemptEvent(EntityUid ItemToInsert, bool Cancelled = false); +/// +/// Raised on the entity storage whenever checking if an entity can be inserted into it. +/// +[ByRefEvent] +public record struct EntityStorageInsertedIntoAttemptEvent(EntityUid ItemToInsert, bool Cancelled = false); + [ByRefEvent] public record struct StorageOpenAttemptEvent(EntityUid User, bool Silent, bool Cancelled = false); diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index 75088bfeec..2b73a9349f 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -343,6 +343,13 @@ public abstract class SharedEntityStorageSystem : EntitySystem if (attemptEvent.Cancelled) return false; + // Allow other components on the container to prevent inserting the item: e.g. the container is folded + var containerAttemptEvent = new EntityStorageInsertedIntoAttemptEvent(toInsert); + RaiseLocalEvent(container, ref containerAttemptEvent); + + if (containerAttemptEvent.Cancelled) + return false; + // Consult the whitelist. The whitelist ignores the default assumption about how entity storage works. if (component.Whitelist != null) return _whitelistSystem.IsValid(component.Whitelist, toInsert);