diff --git a/Content.Shared/Maps/TurfHelpers.cs b/Content.Shared/Maps/TurfHelpers.cs index bc609ebd04..a982e6b561 100644 --- a/Content.Shared/Maps/TurfHelpers.cs +++ b/Content.Shared/Maps/TurfHelpers.cs @@ -152,7 +152,10 @@ namespace Content.Shared.Maps { lookupSystem ??= IoCManager.Resolve(); - return lookupSystem.GetEntitiesIntersecting(turf.MapIndex, GetWorldTileBox(turf), flags); + if (!GetWorldTileBox(turf, out var worldBox)) + return Enumerable.Empty(); + + return lookupSystem.GetEntitiesIntersecting(turf.MapIndex, worldBox, flags); } /// @@ -183,7 +186,8 @@ namespace Content.Shared.Maps { var physics = EntitySystem.Get(); - var worldBox = GetWorldTileBox(turf); + if (!GetWorldTileBox(turf, out var worldBox)) + return false; var query = physics.GetCollidingEntities(turf.MapIndex, in worldBox); @@ -209,20 +213,25 @@ namespace Content.Shared.Maps /// /// Creates a box the size of a tile, at the same position in the world as the tile. /// - private static Box2 GetWorldTileBox(TileRef turf) + private static bool GetWorldTileBox(TileRef turf, out Box2Rotated res) { var map = IoCManager.Resolve(); - // This is scaled to 90 % so it doesn't encompass walls on other tiles. - var tileBox = Box2.UnitCentered.Scale(0.9f); - if (map.TryGetGrid(turf.GridIndex, out var tileGrid)) { + // This is scaled to 90 % so it doesn't encompass walls on other tiles. + var tileBox = Box2.UnitCentered.Scale(0.9f); tileBox = tileBox.Scale(tileGrid.TileSize); - return tileBox.Translated(tileGrid.GridTileToWorldPos(turf.GridIndices)); + var worldPos = tileGrid.GridTileToWorldPos(turf.GridIndices); + tileBox = tileBox.Translated(worldPos); + // Now tileBox needs to be rotated to match grid rotation + res = new Box2Rotated(tileBox, tileGrid.WorldRotation, worldPos); + return true; } - return tileBox; + // Have to "return something" + res = Box2Rotated.UnitCentered; + return false; } } }