_xformQuery = GetEntityQuery<TransformComponent>();
SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup);
+ SubscribeLocalEvent<DisposalHolderComponent, ContainerIsInsertingAttemptEvent>(CanInsert);
+ SubscribeLocalEvent<DisposalHolderComponent, EntInsertedIntoContainerMessage>(OnInsert);
}
private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
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))
- return false;
- 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;
+ if (!HasComp<ItemComponent>(args.EntityUid) && !HasComp<BodyComponent>(args.EntityUid))
+ args.Cancel();
}
- private bool CanInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null)
+ private void OnInsert(Entity<DisposalHolderComponent> ent, ref EntInsertedIntoContainerMessage args)
{
- if (!Resolve(uid, ref holder))
- return false;
-
- if (!_containerSystem.CanInsert(toInsert, holder.Container))
- {
- return false;
- }
-
- return HasComp<ItemComponent>(toInsert) ||
- HasComp<BodyComponent>(toInsert);
+ if (_physicsQuery.TryGetComponent(args.Entity, out var physBody))
+ _physicsSystem.SetCanCollide(args.Entity, false, body: physBody);
}
public void ExitDisposals(EntityUid uid, DisposalHolderComponent? holder = null, TransformComponent? holderTransform = null)