CatStation/Content.Server/Tiles/RequiresTileSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

42 lines
1.1 KiB
C#

using Content.Shared.Tiles;
using Robust.Shared.Map.Components;
using Robust.Shared.Map.Enumerators;
namespace Content.Server.Tiles;
public sealed partial class RequiresTileSystem : EntitySystem
{
/*
* Needs to be on server as client can't predict QueueDel.
*/
[Dependency] private SharedMapSystem _maps = default!;
private EntityQuery<RequiresTileComponent> _tilesQuery;
public override void Initialize()
{
base.Initialize();
_tilesQuery = GetEntityQuery<RequiresTileComponent>();
SubscribeLocalEvent<TileChangedEvent>(OnTileChange);
}
private void OnTileChange(ref TileChangedEvent ev)
{
if (!TryComp<MapGridComponent>(ev.Entity, out var grid))
return;
foreach (var change in ev.Changes)
{
var anchored = _maps.GetAnchoredEntitiesEnumerator(ev.Entity, grid, change.GridIndices);
while (anchored.MoveNext(out var ent))
{
if (!_tilesQuery.HasComponent(ent.Value))
continue;
QueueDel(ent.Value);
}
}
}
}