Files
RobustToolbox/Robust.Shared/Containers/SharedContainerSystem.cs
ShadowCommander e16e0f4bd0 Fix containers with entities that do not exist yet (#1892)
* Fix containers that hold entities not on client

* Delete from ExpectedEntities when entity removed

* Fix ContainerSystem not registering on the server

* Move container state to entity system
Move client code to client

* Fix removal and clean up code

* Add test

* Add more checks to test

* Remove unneeded deletion event handler

When the child is deleted, if the entity does not exist on the client,
then HandleComponentState runs. If the entity does exist, then
HandleEntityInitialized would have run. Either way HandleEntityDeleted
is not needed.

* Renamed unexpected to removedExpected
2021-08-04 19:00:14 -07:00

30 lines
906 B
C#

using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Containers
{
public abstract class SharedContainerSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
{
base.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);
}
}
}