Fix magnet despawning deletion (#23657)

Silly mechanic.
This commit is contained in:
metalgearsloth
2024-01-07 17:40:49 +11:00
committed by GitHub
parent 23ec7d8554
commit 0fc5bf5546

View File

@@ -18,6 +18,8 @@ public sealed partial class SalvageSystem
private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery; private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
private List<(Entity<TransformComponent> Entity, EntityUid MapUid)> _detachEnts = new();
private void InitializeMagnet() private void InitializeMagnet()
{ {
_salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>(); _salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>();
@@ -134,13 +136,16 @@ public sealed partial class SalvageSystem
// Uhh yeah don't delete mobs or whatever // Uhh yeah don't delete mobs or whatever
var mobQuery = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent, TransformComponent>(); var mobQuery = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent, TransformComponent>();
_detachEnts.Clear();
while (mobQuery.MoveNext(out var mobUid, out _, out _, out var xform)) while (mobQuery.MoveNext(out var mobUid, out _, out _, out var xform))
{ {
if (xform.GridUid == null || !data.Comp.ActiveEntities.Contains(xform.GridUid.Value) || xform.MapUid == null) if (xform.GridUid == null || !data.Comp.ActiveEntities.Contains(xform.GridUid.Value) || xform.MapUid == null)
continue; continue;
_transform.SetParent(mobUid, xform.MapUid.Value); // Can't parent directly to map as it runs grid traversal.
_detachEnts.Add(((mobUid, xform), xform.MapUid.Value));
_transform.DetachParentToNull(mobUid, xform);
} }
// Go and cleanup the active ents. // Go and cleanup the active ents.
@@ -149,6 +154,11 @@ public sealed partial class SalvageSystem
Del(ent); Del(ent);
} }
foreach (var entity in _detachEnts)
{
_transform.SetParent(entity.Entity.Owner, entity.Entity.Comp, entity.MapUid);
}
data.Comp.ActiveEntities = null; data.Comp.ActiveEntities = null;
} }