55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Global.Shared.API;
|
|
using HarmonyLib;
|
|
using Sandbox.Game.Entities;
|
|
using VRage.Game.Entity;
|
|
using VRageMath;
|
|
|
|
namespace Global.Shared.Patches
|
|
{
|
|
[HarmonyPatch(typeof(MyGamePruningStructure))]
|
|
public class MyGamePruningStructurePatch
|
|
{
|
|
private static readonly List<IGridData> _gridQueryStorage = new List<IGridData>();
|
|
private static readonly List<IControllableEntityData> _queryStorage = new List<IControllableEntityData>();
|
|
|
|
// [HarmonyPatch("GetTopMostEntitiesInBox")]
|
|
// [HarmonyPrefix]
|
|
public static bool GetTopMostEntitiesInBox(
|
|
ref BoundingBoxD box,
|
|
List<MyEntity> result,
|
|
MyEntityQueryType qtype = MyEntityQueryType.Both)
|
|
{
|
|
GetTopMostBox(ref box, result, qtype);
|
|
return false;
|
|
}
|
|
|
|
public static void GetTopMostBox(ref BoundingBoxD box, List<MyEntity> result, MyEntityQueryType qType)
|
|
{
|
|
_queryStorage.Clear();
|
|
_gridQueryStorage.Clear();
|
|
var gridSearch = GridFlag.None;
|
|
if (qType.HasDynamic()) gridSearch |= GridFlag.DynamicGrid;
|
|
if (qType.HasStatic()) gridSearch |= GridFlag.StaticGrid;
|
|
if (gridSearch != GridFlag.None) GlobalAPI.LocateGrids(_gridQueryStorage, box, gridSearch);
|
|
|
|
result.AddRange(_gridQueryStorage.Select(e => e.CubeGrid));
|
|
|
|
if (qType.HasDynamic()) GlobalAPI.LocateCharacters(_queryStorage, box, PlayerFlag.Character);
|
|
|
|
result.AddRange(_queryStorage.Select(l => l.Entity.Entity));
|
|
}
|
|
|
|
// [HarmonyPatch("GetAllTopMostStaticEntitiesInBox")]
|
|
// [HarmonyPrefix]
|
|
public static bool GetAllTopMostStaticEntitiesInBox(
|
|
ref BoundingBoxD box,
|
|
List<MyEntity> result,
|
|
MyEntityQueryType qtype = MyEntityQueryType.Both)
|
|
{
|
|
GetTopMostBox(ref box, result, qtype);
|
|
return false;
|
|
}
|
|
}
|
|
} |