mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
31 lines
1004 B
C#
31 lines
1004 B
C#
using Robust.Shared.GameObjects.EntitySystemMessages;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.GameObjects.Components;
|
|
|
|
namespace Robust.Server.GameObjects.EntitySystems
|
|
{
|
|
internal sealed class ContainerSystem : EntitySystem
|
|
{
|
|
public override void SubscribeEvents()
|
|
{
|
|
base.SubscribeEvents();
|
|
|
|
SubscribeEvent<EntParentChangedMessage>(HandleParentChanged);
|
|
}
|
|
|
|
// Eject entities from their parent container if the parent change is done by the transform only.
|
|
private static void HandleParentChanged(object sender, EntParentChangedMessage message)
|
|
{
|
|
var oldParentEntity = message.OldParent;
|
|
|
|
if (oldParentEntity == null || !oldParentEntity.IsValid())
|
|
return;
|
|
|
|
if (oldParentEntity.TryGetComponent(out IContainerManager containerManager))
|
|
{
|
|
containerManager.ForceRemove(message.Entity);
|
|
}
|
|
}
|
|
}
|
|
}
|