private void InventoryInit() { using (MyCube.Pin()) { if (InventoryInited || !MyCube.HasInventory || MyCube.MarkedForClose || (Platform.State != MyWeaponPlatform.PlatformState.Inited && Platform.State != MyWeaponPlatform.PlatformState.Incomplete) || BlockInventory == null) { Platform.PlatformCrash(this, false, true, $"InventoryInit failed: IsInitted:{InventoryInited} - NoInventory:{!MyCube.HasInventory} - Marked:{MyCube.MarkedForClose} - PlatformNotReady:{Platform.State != MyWeaponPlatform.PlatformState.Ready}({Platform.State}) - nullInventory:{BlockInventory == null}"); return; } if (MyCube is IMyConveyorSorter || BlockInventory.Constraint == null) { BlockInventory.Constraint = new MyInventoryConstraint("ammo"); } BlockInventory.Constraint.m_useDefaultIcon = false; BlockInventory.Refresh(); BlockInventory.Constraint.Clear(); if (!string.IsNullOrEmpty(CustomIcon)) { var iconPath = Platform.Structure.ModPath + "\\Textures\\GUI\\Icons\\" + CustomIcon; BlockInventory.Constraint.Icon = iconPath; BlockInventory.Constraint.UpdateIcon(); } for (int i = 0; i < Platform.Weapons.Length; i++) { var w = Platform.Weapons[i]; if (w == null) { Log.Line($"InventoryInit weapon null"); continue; } for (int j = 0; j < w.System.AmmoTypes.Length; j++) { if (w.System.AmmoTypes[j].AmmoDef.Const.MagazineDef != null) { BlockInventory.Constraint.Add(w.System.AmmoTypes[j].AmmoDef.Const.MagazineDef.Id); } } } BlockInventory.Refresh(); InventoryInited = true; } }
private void InventoryInit() { using (MyCube?.Pin()) { if (InventoryInited || MyCube == null || !MyCube.HasInventory || MyCube.MarkedForClose || Platform == null || Platform.State == MyWeaponPlatform.PlatformState.Invalid || Platform.Weapons?.Length == 0 || BlockInventory == null) { return; } if (MyCube is IMyConveyorSorter || BlockInventory.Constraint == null) { BlockInventory.Constraint = new MyInventoryConstraint("ammo"); } BlockInventory.Constraint.m_useDefaultIcon = false; BlockInventory.ResetVolume(); BlockInventory.Refresh(); BlockInventory.Constraint.Clear(); var maxInventoryVolume = 0f; for (int i = 0; i < Platform.Weapons.Length; i++) { var w = Platform.Weapons[i]; if (w == null) { continue; } for (int j = 0; j < w.System?.WeaponAmmoTypes?.Length; j++) { if (w.System.WeaponAmmoTypes[j].AmmoDef.Const.MagazineDef != null) { BlockInventory.Constraint.Add(w.System.WeaponAmmoTypes[j].AmmoDef.Const.MagazineDef.Id); } } maxInventoryVolume += w.System?.MaxAmmoVolume ?? 0; } BlockInventory.FixInventoryVolume(maxInventoryVolume); BlockInventory.Refresh(); InventoryInited = true; } }