mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
This means all invocations of TryGetComponent now need a nullable parameter because, well, the result can be null. that's the point.
29 lines
956 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|