public void UnRegisterSubGrid(MyCubeGrid grid, bool clean = false) { if (!SubGridsRegistered.Contains(grid)) { Log.Line($"sub Grid Already UnRegistered: [Main]:{grid == MyGrid}"); } if (!clean) { SubGrids.Remove(grid); } SubGridsRegistered.Remove(grid); grid.OnFatBlockAdded -= FatBlockAdded; grid.OnFatBlockRemoved -= FatBlockRemoved; foreach (var cube in grid.GetFatBlocks()) { var battery = cube as MyBatteryBlock; if (InventoryMonitor.ContainsKey(cube) || battery != null && Batteries.Contains(battery)) { FatBlockRemoved(cube); } } GridAi removeAi; if (!Session.GridTargetingAIs.ContainsKey(grid)) { Session.GridToMasterAi.TryRemove(grid, out removeAi); } }