// This function does some modifications to the cube block's object builder before it's built, usually integrity changes, etc... public virtual void BeforeCreateBlock(MyCubeBlockDefinition definition, MyEntity builder, MyObjectBuilder_CubeBlock ob, bool buildAsAdmin) { if (definition.EntityComponents == null) return; if (ob.ComponentContainer == null) { ob.ComponentContainer = new MyObjectBuilder_ComponentContainer(); } foreach (var componentOb in definition.EntityComponents) { var data = new MyObjectBuilder_ComponentContainer.ComponentData(); data.TypeId = componentOb.Key.ToString(); data.Component = componentOb.Value; ob.ComponentContainer.Components.Add(data); } }
public MyObjectBuilder_CubeBlock ConvertToOriginalBlocksWithFractureComponent() { List<MyObjectBuilder_CubeBlock> blockBuilders = new List<MyObjectBuilder_CubeBlock>(); Quaternion q; for (int i = 0; i < OriginalBlocks.Count; ++i) { var defId = OriginalBlocks[i]; MyCubeBlockDefinition def; MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out def); if (def == null) { Debug.Fail("Cube block definition not found"); continue; } var orientation = Orientations[i]; MultiBlockPartInfo multiBlockInfo = MultiBlocks != null && MultiBlocks.Count > i ? MultiBlocks[i] : null; MyObjectBuilder_CubeBlock blockBuilder = MyObjectBuilderSerializer.CreateNewObject(defId) as MyObjectBuilder_CubeBlock; orientation.GetQuaternion(out q); blockBuilder.Orientation = q; blockBuilder.Min = Position; blockBuilder.MultiBlockId = multiBlockInfo != null ? multiBlockInfo.MultiBlockId : 0; blockBuilder.MultiBlockDefinition = null; if (multiBlockInfo != null) blockBuilder.MultiBlockDefinition = multiBlockInfo.MultiBlockDefinition; blockBuilder.ComponentContainer = new MyObjectBuilder_ComponentContainer(); var fractureBuilder = new MyObjectBuilder_FractureComponentCubeBlock(); m_tmpNamesAndBuildProgress.Clear(); GetAllBlockBreakableShapeNames(def, m_tmpNamesAndBuildProgress); float buildProgress; ConvertAllShapesToFractureComponentShapeBuilder(Shape, ref Matrix.Identity, orientation, m_tmpNamesAndBuildProgress, fractureBuilder, out buildProgress); m_tmpNamesAndBuildProgress.Clear(); // Count of shapes can be 0! if (fractureBuilder.Shapes.Count == 0) continue; float previousBuildRatioUpperBound = 0f; if (def.BuildProgressModels != null) { foreach (var progress in def.BuildProgressModels) { if (progress.BuildRatioUpperBound >= buildProgress) break; previousBuildRatioUpperBound = progress.BuildRatioUpperBound; } } var componentData = new MyObjectBuilder_ComponentContainer.ComponentData(); componentData.TypeId = typeof(MyFractureComponentBase).Name; componentData.Component = fractureBuilder; blockBuilder.ComponentContainer.Components.Add(componentData); blockBuilder.BuildPercent = buildProgress; Debug.Assert(buildProgress > previousBuildRatioUpperBound); blockBuilder.IntegrityPercent = MyDefinitionManager.Static.DestructionDefinition.ConvertedFractureIntegrityRatio * buildProgress; if (i == 0 && CubeGrid.GridSizeEnum == MyCubeSize.Small) return blockBuilder; blockBuilders.Add(blockBuilder); } if (blockBuilders.Count > 0) { MyObjectBuilder_CompoundCubeBlock compoundBuilder = MyCompoundCubeBlock.CreateBuilder(blockBuilders); return compoundBuilder; } return null; }