public static IMySlimBlock GetItemAsSlimBlock(SyncEntityId id) { var item = GetItem(id); var slimBlock = item as IMySlimBlock; if (slimBlock != null) { return(slimBlock); } var block = item as IMyCubeBlock; if (block != null) { return(block.SlimBlock); } return(null); }
public static object GetItem(SyncEntityId id) { if (id == null) { return(null); } if (id.EntityId != 0) { IMyEntity entity; if (MyAPIGateway.Entities.TryGetEntityById(id.EntityId, out entity)) { return(entity); } } if (id.GridId != 0 && id.Position != null) { IMyEntity entity; if (MyAPIGateway.Entities.TryGetEntityById(id.GridId, out entity)) { var grid = entity as IMyCubeGrid; return(grid != null?grid.GetCubeBlock(id.Position.Value) : null); } } if (id.Position != null) { return(id.Position); } if (id.Box != null) { IMyEntity entity; var box = id.Box.Value; if ((entity = MyAPIGateway.Session.VoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref box, null)) != null) { return(entity); } } return(null); }
public static T GetItemAs <T>(SyncEntityId id) where T : class { return(GetItem(id) as T); }