private static void GetMaterialsSimple(MyCubeBlockDefinition definition, MyComponentList output) { for (int i = 0; i < definition.Components.Length; ++i) { var component = definition.Components[i]; output.AddMaterial(component.Definition.Id, component.Count, i == 0 ? 1 : 0); } return; }
static private void AddSingleBlockRequirements(MyObjectBuilder_CubeBlock block, MyComponentList buildComponents) { MyComponentStack.GetMountedComponents(buildComponents, block); if (block.ConstructionStockpile != null) foreach (var item in block.ConstructionStockpile.Items) { if (item.PhysicalContent != null) buildComponents.AddMaterial(item.PhysicalContent.GetId(), item.Amount, addToDisplayList: false); } }
public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block) { int topGroup = 0; int topComponent = 0; MyCubeBlockDefinition blockDef = null; MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef); Debug.Assert(blockDef != null, "Could not find block definition"); if (blockDef == null) return; Debug.Assert(block!= null, "Getting mounted components of a null block"); if (block == null) return; float integrity = block.IntegrityPercent * blockDef.MaxIntegrity; CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent); Debug.Assert(topGroup < blockDef.Components.Count(), "Component group overflow in CalculateItemRequirements"); if (topGroup >= blockDef.Components.Count()) return; Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements"); if (topComponent >= blockDef.Components[topGroup].Count) return; int mountCount = topComponent; if (integrity >= MOUNT_THRESHOLD) mountCount++; MyDefinitionId componentId; for (int group = 0; group < topGroup; ++group) { MyCubeBlockDefinition.Component component = blockDef.Components[group]; addToList.AddMaterial(component.Definition.Id, component.Count, addToDisplayList: false); } componentId = blockDef.Components[topGroup].Definition.Id; addToList.AddMaterial(componentId, mountCount, addToDisplayList: false); }