Improve some BinSystem functionality (#38262)
* BinSystem improvements * Prevent double-add
This commit is contained in:
@@ -20,6 +20,12 @@ public sealed partial class BinComponent : Component
|
||||
[ViewVariables]
|
||||
public Container ItemContainer = default!;
|
||||
|
||||
/// <summary>
|
||||
/// ID of the container used to hold the items in the bin.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public string ContainerId = "bin-container";
|
||||
|
||||
/// <summary>
|
||||
/// A list representing the order in which
|
||||
/// all the entities are stored in the bin.
|
||||
|
||||
@@ -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";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<BinComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<BinComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<BinComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
SubscribeLocalEvent<BinComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
SubscribeLocalEvent<BinComponent, InteractHandEvent>(OnInteractHand, before: new[] { typeof(SharedItemSystem) });
|
||||
SubscribeLocalEvent<BinComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
@@ -45,7 +44,7 @@ public sealed class BinSystem : EntitySystem
|
||||
|
||||
private void OnStartup(EntityUid uid, BinComponent component, ComponentStartup args)
|
||||
{
|
||||
component.ItemContainer = _container.EnsureContainer<Container>(uid, BinContainerId);
|
||||
component.ItemContainer = _container.EnsureContainer<Container>(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<BinComponent> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user