Files
RobustToolbox/Robust.Server/GameObjects/EntitySystems/ContainerSystem.cs
T
Pieter-Jan Briers d4fc0517c4 Fix IEntity.TryGetComponent nullability signatures.
This means all invocations of TryGetComponent now need a nullable parameter because, well, the result can be null. that's the point.
2020-08-20 15:31:18 +02:00

29 lines
956 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 Initialize()
{
SubscribeLocalEvent<EntParentChangedMessage>(HandleParentChanged);
}
// Eject entities from their parent container if the parent change is done by the transform only.
private static void HandleParentChanged(EntParentChangedMessage message)
{
var oldParentEntity = message.OldParent;
if (oldParentEntity == null || !oldParentEntity.IsValid())
return;
if (oldParentEntity.TryGetComponent(out IContainerManager? containerManager))
{
containerManager.ForceRemove(message.Entity);
}
}
}
}