From e01d7e69ea0c9529780ec9750cff8350a5f80654 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 01:54:07 -0700 Subject: [PATCH 1/5] Move placeable check to PlaceableSurfaceSystem This check stops entities from being inserted into a storage entity when it has a PlaceableSurfaceComponent. The entity is instead placed on top of the entity like a table. --- Content.Shared/Placeable/PlaceableSurfaceSystem.cs | 7 +++++++ .../Storage/EntitySystems/SharedStorageSystem.cs | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs index a9a9390a6e0e98..1237a0a9022b39 100644 --- a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs +++ b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs @@ -1,6 +1,7 @@ using System.Numerics; using Content.Shared.Hands.EntitySystems; using Content.Shared.Interaction; +using Content.Shared.Storage; using Content.Shared.Storage.Components; namespace Content.Shared.Placeable; @@ -14,6 +15,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnAfterInteractUsing); + SubscribeLocalEvent(OnStorageInteractAttempt); } public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null) @@ -66,4 +68,9 @@ private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surfa args.Handled = true; } + + private void OnStorageInteractAttempt(Entity ent, ref StorageInteractAttemptEvent args) + { + args.Cancelled = true; + } } diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 18a8f20afc7e6a..b4745e9baff9aa 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -349,9 +349,6 @@ private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, Intera if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false)) return; - if (HasComp(uid)) - return; - PlayerInsertHeldEntity(uid, args.User, storageComp); // Always handle it, even if insertion fails. // We don't want to trigger any AfterInteract logic here. From 2bf124e5e33d25002970a7237e4560a555a86d5a Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 01:59:28 -0700 Subject: [PATCH 2/5] Move SetPlaceable to PlaceableSurfaceSystem --- Content.Shared/Placeable/PlaceableSurfaceSystem.cs | 12 ++++++++++++ .../EntitySystems/SharedEntityStorageSystem.cs | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs index 1237a0a9022b39..203a44c2bc8bb6 100644 --- a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs +++ b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs @@ -16,6 +16,8 @@ public override void Initialize() SubscribeLocalEvent(OnAfterInteractUsing); SubscribeLocalEvent(OnStorageInteractAttempt); + SubscribeLocalEvent(OnStorageAfterOpen); + SubscribeLocalEvent(OnStorageAfterClose); } public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null) @@ -73,4 +75,14 @@ private void OnStorageInteractAttempt(Entity ent, ref { args.Cancelled = true; } + + private void OnStorageAfterOpen(Entity ent, ref StorageAfterOpenEvent args) + { + SetPlaceable(ent.Owner, true, ent.Comp); + } + + private void OnStorageAfterClose(Entity ent, ref StorageAfterCloseEvent args) + { + SetPlaceable(ent.Owner, false, ent.Comp); + } } diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index 636c6038348097..39b5c0ddc08bbc 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -485,9 +485,6 @@ private void ModifyComponents(EntityUid uid, SharedEntityStorageComponent? compo } } - if (TryComp(uid, out var surface)) - _placeableSurface.SetPlaceable(uid, component.Open, surface); - _appearance.SetData(uid, StorageVisuals.Open, component.Open); _appearance.SetData(uid, StorageVisuals.HasContents, component.Contents.ContainedEntities.Count > 0); } From 7a99a19105dd2c9a263a49b2d5d2ca7a1bc8cfd5 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 02:13:38 -0700 Subject: [PATCH 3/5] Update to transform system and consolidate code --- Content.Shared/Placeable/PlaceableSurfaceSystem.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs index 203a44c2bc8bb6..68e88b04eaf0e0 100644 --- a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs +++ b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs @@ -9,6 +9,7 @@ namespace Content.Shared.Placeable; public sealed class PlaceableSurfaceSystem : EntitySystem { [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly SharedTransformSystem _transformSystem = default!; public override void Initialize() { @@ -63,10 +64,8 @@ private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surfa if (!_handsSystem.TryDrop(args.User, args.Used)) return; - if (surface.PlaceCentered) - Transform(args.Used).LocalPosition = Transform(uid).LocalPosition + surface.PositionOffset; - else - Transform(args.Used).Coordinates = args.ClickLocation; + _transformSystem.SetCoordinates(args.Used, + surface.PlaceCentered ? Transform(uid).Coordinates.Offset(surface.PositionOffset) : args.ClickLocation); args.Handled = true; } From 6491b3dd53d95780757074df810e7df44fc6c2d0 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 02:38:19 -0700 Subject: [PATCH 4/5] Fix interaction with storage that has a placeable component --- Content.Shared/Placeable/PlaceableSurfaceSystem.cs | 4 ++-- Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs | 5 +++++ Content.Shared/Storage/StorageComponent.cs | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs index 68e88b04eaf0e0..32171ed8d91389 100644 --- a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs +++ b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs @@ -16,7 +16,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnAfterInteractUsing); - SubscribeLocalEvent(OnStorageInteractAttempt); + SubscribeLocalEvent(OnStorageInteractUsingAttempt); SubscribeLocalEvent(OnStorageAfterOpen); SubscribeLocalEvent(OnStorageAfterClose); } @@ -70,7 +70,7 @@ private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surfa args.Handled = true; } - private void OnStorageInteractAttempt(Entity ent, ref StorageInteractAttemptEvent args) + private void OnStorageInteractUsingAttempt(Entity ent, ref StorageInteractUsingAttemptEvent args) { args.Cancelled = true; } diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index b4745e9baff9aa..0a1363e5cefffb 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -349,6 +349,11 @@ private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, Intera if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false)) return; + var attemptEv = new StorageInteractUsingAttemptEvent(); + RaiseLocalEvent(uid, ref attemptEv); + if (attemptEv.Cancelled) + return; + PlayerInsertHeldEntity(uid, args.User, storageComp); // Always handle it, even if insertion fails. // We don't want to trigger any AfterInteract logic here. diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs index 2860f8dacfe82c..4b5c2158e1c84c 100644 --- a/Content.Shared/Storage/StorageComponent.cs +++ b/Content.Shared/Storage/StorageComponent.cs @@ -230,6 +230,9 @@ public AnimateInsertingEntitiesEvent(NetEntity storage, List storedEn [ByRefEvent] public record struct StorageInteractAttemptEvent(bool Silent, bool Cancelled = false); + [ByRefEvent] + public record struct StorageInteractUsingAttemptEvent(bool Cancelled = false); + [NetSerializable] [Serializable] public enum StorageVisuals : byte From 470d418c3b8151ac424938edfcbb32fe108d51fa Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Thu, 19 Sep 2024 17:42:13 +1000 Subject: [PATCH 5/5] deadlock --- Content.Shared/Placeable/PlaceableSurfaceSystem.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs index 32171ed8d91389..c332064ea38eae 100644 --- a/Content.Shared/Placeable/PlaceableSurfaceSystem.cs +++ b/Content.Shared/Placeable/PlaceableSurfaceSystem.cs @@ -26,6 +26,9 @@ public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceCompon if (!Resolve(uid, ref surface, false)) return; + if (surface.IsPlaceable == isPlaceable) + return; + surface.IsPlaceable = isPlaceable; Dirty(uid, surface); }