CatStation/Content.Shared/Containers/ContainerCompSystem.cs
Whatstone a8453723d8
Cleanup: ProtoMan Part 1 - remove Shared EntitySystem IPrototypeManager instances (#44386)
* Remove Shared System IPrototypeManager instances

* Remove RecipeManager IPrototypeManager instance

* Fix ItemSystem IPrototypeManager refs, use TryComp

* SharedItemSystem changes, EntWhitelist CompName

* HasComponent->HasComp
2026-06-29 10:18:44 +00:00

41 lines
1.4 KiB
C#

using Robust.Shared.Containers;
using Robust.Shared.Timing;
namespace Content.Shared.Containers;
/// <summary>
/// Applies / removes an entity prototype from a child entity when it's inserted into a container.
/// </summary>
public sealed partial class ContainerCompSystem : EntitySystem
{
[Dependency] private IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ContainerCompComponent, EntInsertedIntoContainerMessage>(OnConInsert);
SubscribeLocalEvent<ContainerCompComponent, EntRemovedFromContainerMessage>(OnConRemove);
}
private void OnConRemove(Entity<ContainerCompComponent> ent, ref EntRemovedFromContainerMessage args)
{
if (args.Container.ID != ent.Comp.Container || _timing.ApplyingState)
return;
if (ProtoMan.Resolve(ent.Comp.Proto, out var entProto))
{
EntityManager.RemoveComponents(args.Entity, entProto.Components);
}
}
private void OnConInsert(Entity<ContainerCompComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (args.Container.ID != ent.Comp.Container || _timing.ApplyingState)
return;
if (ProtoMan.Resolve(ent.Comp.Proto, out var entProto))
{
EntityManager.AddComponents(args.Entity, entProto.Components);
}
}
}