Cleanup: Remove `TryInsert method from the DisposableSystem` and use event subscriptions instead (#38819)

Cleanup
This commit is contained in:
Winkarst-cpu
2025-07-07 22:13:35 +03:00
committed by GitHub
parent 1c59e087d5
commit bb02be1dc7
2 changed files with 9 additions and 25 deletions

View File

@@ -428,7 +428,7 @@ namespace Content.Server.Disposal.Tube
foreach (var entity in from.Container.ContainedEntities.ToArray()) foreach (var entity in from.Container.ContainedEntities.ToArray())
{ {
_disposableSystem.TryInsert(holder, entity, holderComponent); _containerSystem.Insert(entity, holderComponent.Container);
} }
_atmosSystem.Merge(holderComponent.Air, from.Air); _atmosSystem.Merge(holderComponent.Air, from.Air);

View File

@@ -43,6 +43,8 @@ namespace Content.Server.Disposal.Unit
_xformQuery = GetEntityQuery<TransformComponent>(); _xformQuery = GetEntityQuery<TransformComponent>();
SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup); SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<DisposalHolderComponent, ContainerIsInsertingAttemptEvent>(CanInsert);
SubscribeLocalEvent<DisposalHolderComponent, EntInsertedIntoContainerMessage>(OnInsert);
} }
private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args) private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
@@ -50,34 +52,16 @@ namespace Content.Server.Disposal.Unit
holder.Container = _containerSystem.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent)); holder.Container = _containerSystem.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent));
} }
public bool TryInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null) private void CanInsert(Entity<DisposalHolderComponent> ent, ref ContainerIsInsertingAttemptEvent args)
{ {
if (!Resolve(uid, ref holder)) if (!HasComp<ItemComponent>(args.EntityUid) && !HasComp<BodyComponent>(args.EntityUid))
return false; args.Cancel();
if (!CanInsert(uid, toInsert, holder))
return false;
if (!_containerSystem.Insert(toInsert, holder.Container))
return false;
if (_physicsQuery.TryGetComponent(toInsert, out var physBody))
_physicsSystem.SetCanCollide(toInsert, false, body: physBody);
return true;
} }
private bool CanInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null) private void OnInsert(Entity<DisposalHolderComponent> ent, ref EntInsertedIntoContainerMessage args)
{ {
if (!Resolve(uid, ref holder)) if (_physicsQuery.TryGetComponent(args.Entity, out var physBody))
return false; _physicsSystem.SetCanCollide(args.Entity, false, body: physBody);
if (!_containerSystem.CanInsert(toInsert, holder.Container))
{
return false;
}
return HasComp<ItemComponent>(toInsert) ||
HasComp<BodyComponent>(toInsert);
} }
public void ExitDisposals(EntityUid uid, DisposalHolderComponent? holder = null, TransformComponent? holderTransform = null) public void ExitDisposals(EntityUid uid, DisposalHolderComponent? holder = null, TransformComponent? holderTransform = null)