From 00789525f896af03f969087bb3e3b82e3a5c597d Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Wed, 11 Jun 2025 14:04:30 -0400 Subject: [PATCH] Improve some `BinSystem` functionality (#38262) * BinSystem improvements * Prevent double-add --- Content.Shared/Storage/Components/BinComponent.cs | 6 ++++++ Content.Shared/Storage/EntitySystems/BinSystem.cs | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Content.Shared/Storage/Components/BinComponent.cs b/Content.Shared/Storage/Components/BinComponent.cs index 99e2a9844a..03967d7fc9 100644 --- a/Content.Shared/Storage/Components/BinComponent.cs +++ b/Content.Shared/Storage/Components/BinComponent.cs @@ -20,6 +20,12 @@ public sealed partial class BinComponent : Component [ViewVariables] public Container ItemContainer = default!; + /// + /// ID of the container used to hold the items in the bin. + /// + [DataField] + public string ContainerId = "bin-container"; + /// /// A list representing the order in which /// all the entities are stored in the bin. diff --git a/Content.Shared/Storage/EntitySystems/BinSystem.cs b/Content.Shared/Storage/EntitySystems/BinSystem.cs index 8c2cb4c4fc..3b57dd8fea 100644 --- a/Content.Shared/Storage/EntitySystems/BinSystem.cs +++ b/Content.Shared/Storage/EntitySystems/BinSystem.cs @@ -24,13 +24,12 @@ public sealed class BinSystem : EntitySystem [Dependency] private readonly SharedHandsSystem _hands = default!; [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; - public const string BinContainerId = "bin-container"; - /// public override void Initialize() { SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnEntInserted); SubscribeLocalEvent(OnEntRemoved); SubscribeLocalEvent(OnInteractHand, before: new[] { typeof(SharedItemSystem) }); SubscribeLocalEvent(OnAfterInteractUsing); @@ -45,7 +44,7 @@ public sealed class BinSystem : EntitySystem private void OnStartup(EntityUid uid, BinComponent component, ComponentStartup args) { - component.ItemContainer = _container.EnsureContainer(uid, BinContainerId); + component.ItemContainer = _container.EnsureContainer(uid, component.ContainerId); } private void OnMapInit(EntityUid uid, BinComponent component, MapInitEvent args) @@ -66,6 +65,11 @@ public sealed class BinSystem : EntitySystem } } + private void OnEntInserted(Entity ent, ref EntInsertedIntoContainerMessage args) + { + ent.Comp.Items.Add(args.Entity); + } + private void OnEntRemoved(EntityUid uid, BinComponent component, EntRemovedFromContainerMessage args) { component.Items.Remove(args.Entity); @@ -96,7 +100,7 @@ public sealed class BinSystem : EntitySystem if (args.Using != null) { var canReach = args.CanAccess && args.CanInteract; - InsertIntoBin(args.User, args.Target, (EntityUid) args.Using, component, false, canReach); + InsertIntoBin(args.User, args.Target, (EntityUid)args.Using, component, false, canReach); } } @@ -136,7 +140,6 @@ public sealed class BinSystem : EntitySystem return false; _container.Insert(toInsert, component.ItemContainer); - component.Items.Add(toInsert); Dirty(uid, component); return true; } -- 2.51.2