diff --git a/Content.Server/AME/AMENodeGroup.cs b/Content.Server/AME/AMENodeGroup.cs index 6f032522db..83af931630 100644 --- a/Content.Server/AME/AMENodeGroup.cs +++ b/Content.Server/AME/AMENodeGroup.cs @@ -37,14 +37,21 @@ namespace Content.Server.AME base.LoadNodes(groupNodes); var mapManager = IoCManager.Resolve(); - var grid = mapManager.GetGrid(GridId); + IMapGrid? grid = null; foreach (var node in groupNodes) { var nodeOwner = node.Owner; if (_entMan.TryGetComponent(nodeOwner, out AMEShieldComponent? shield)) { - var nodeNeighbors = grid.GetCellsInSquareArea(_entMan.GetComponent(nodeOwner).Coordinates, 1) + var xform = _entMan.GetComponent(nodeOwner); + if (xform.GridUid != grid?.GridEntityId && !mapManager.TryGetGrid(xform.GridUid, out grid)) + continue; + + if (grid == null) + continue; + + var nodeNeighbors = grid.GetCellsInSquareArea(xform.Coordinates, 1) .Where(entity => entity != nodeOwner && _entMan.HasComponent(entity)); if (nodeNeighbors.Count() >= 8) diff --git a/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs b/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs index cc95bf0eaf..fb0c3dd84b 100644 --- a/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs +++ b/Content.Server/NodeContainer/NodeGroups/BaseNodeGroup.cs @@ -56,9 +56,6 @@ namespace Content.Server.NodeContainer.NodeGroups [ViewVariables] public bool Removed { get; set; } = false; - [ViewVariables] - protected EntityUid GridId { get; private set; } - /// /// Network ID of this group for client-side debug visualization of nodes. /// @@ -75,12 +72,6 @@ namespace Content.Server.NodeContainer.NodeGroups public virtual void Initialize(Node sourceNode, IEntityManager? entMan = null) { - // TODO: Can we get rid of this GridId? - IoCManager.Resolve(ref entMan); - - var xform = entMan.GetComponent(sourceNode.Owner); - DebugTools.AssertNotNull(xform.GridUid); - GridId = xform.GridUid!.Value; } /// diff --git a/Content.Server/NodeContainer/NodeGroups/PipeNet.cs b/Content.Server/NodeContainer/NodeGroups/PipeNet.cs index 3be3c73205..df362354cf 100644 --- a/Content.Server/NodeContainer/NodeGroups/PipeNet.cs +++ b/Content.Server/NodeContainer/NodeGroups/PipeNet.cs @@ -22,13 +22,20 @@ namespace Content.Server.NodeContainer.NodeGroups [ViewVariables] private AtmosphereSystem? _atmosphereSystem; - public EntityUid Grid => GridId; + public EntityUid? Grid { get; private set; } public override void Initialize(Node sourceNode, IEntityManager? entMan = null) { + IoCManager.Resolve(ref entMan); + base.Initialize(sourceNode, entMan); - _atmosphereSystem = EntitySystem.Get(); + Grid = entMan.GetComponent(sourceNode.Owner).GridUid; + + if (Grid == null) + Logger.Error($"Created a pipe network without an associated grid. Pipe networks currently need to be tied to a grid for amtos to work. Source entity: {entMan.ToPrettyString(sourceNode.Owner)}"); + + _atmosphereSystem = entMan.EntitySysManager.GetEntitySystem(); _atmosphereSystem.AddPipeNet(this); } diff --git a/Content.Server/Power/NodeGroups/ApcNet.cs b/Content.Server/Power/NodeGroups/ApcNet.cs index 6bb4bf57d7..300373bd6b 100644 --- a/Content.Server/Power/NodeGroups/ApcNet.cs +++ b/Content.Server/Power/NodeGroups/ApcNet.cs @@ -20,8 +20,6 @@ namespace Content.Server.Power.NodeGroups void RemovePowerProvider(ApcPowerProviderComponent provider); void QueueNetworkReconnect(); - - EntityUid? GridId { get; } } [NodeGroup(NodeGroupID.Apc)] @@ -41,8 +39,6 @@ namespace Content.Server.Power.NodeGroups private IEnumerable AllReceivers => Providers.SelectMany(provider => provider.LinkedReceivers); - EntityUid? IApcNet.GridId => GridId; - [ViewVariables] public PowerState.Network NetworkNode { get; } = new();