private static IEnumerable <MyObjectBuilder_CubeBlock> MirrorCubes(IMyCubeGrid shipEntity, bool integrate, MirrorDirection xMirror, int xAxis, MirrorDirection yMirror, int yAxis, MirrorDirection zMirror, int zAxis)
        {
            var blocks = new List <MyObjectBuilder_CubeBlock>();

            if (xMirror == MirrorDirection.None && yMirror == MirrorDirection.None && zMirror == MirrorDirection.None)
            {
                return(blocks);
            }

            List <IMySlimBlock> cubeBlocks = new List <IMySlimBlock>();

            shipEntity.GetBlocks(cubeBlocks);
            foreach (var block in cubeBlocks)
            {
                MyObjectBuilder_CubeBlock newBlock = (MyObjectBuilder_CubeBlock)block.GetObjectBuilder().Clone();

                // Need to use the Min from the GetObjectBuilder(), as block.Position is NOT representative.
                Vector3I oldMin = newBlock.Min;

                newBlock.EntityId = 0;

                MyObjectBuilder_MotorBase motorBase = newBlock as MyObjectBuilder_MotorBase;
                if (motorBase != null)
                {
                    motorBase.RotorEntityId = 0;
                }

                MyObjectBuilder_PistonBase pistonBase = newBlock as MyObjectBuilder_PistonBase;
                if (pistonBase != null)
                {
                    pistonBase.TopBlockId = 0;
                }

                MyCubeBlockDefinition definition = MyDefinitionManager.Static.GetCubeBlockDefinition(newBlock);

                MyCubeBlockDefinition mirrorDefinition;
                MirrorCubeOrientation(definition, block.Orientation, xMirror, yMirror, zMirror, out mirrorDefinition, out newBlock.BlockOrientation);

                newBlock.SubtypeName = mirrorDefinition.Id.SubtypeName;


                if (definition.Size.X == 1 && definition.Size.Y == 1 && definition.Size.Z == 1)
                {
                    newBlock.Min = oldMin.Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);
                }
                else
                {
                    // resolve size of component, and transform to original orientation.
                    var orientSize = definition.Size.Add(-1).Transform(block.Orientation).Abs();

                    var min      = oldMin.Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);
                    var blockMax = new SerializableVector3I(oldMin.X + orientSize.X, oldMin.Y + orientSize.Y, oldMin.Z + orientSize.Z);
                    var max      = ((Vector3I)blockMax).Mirror(xMirror, xAxis, yMirror, yAxis, zMirror, zAxis);

                    if (xMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(max.X, min.Y, min.Z);
                    }
                    if (yMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(min.X, max.Y, min.Z);
                    }
                    if (zMirror != MirrorDirection.None)
                    {
                        newBlock.Min = new SerializableVector3I(min.X, min.Y, max.Z);
                    }
                }

                Vector3I newPosition = ComputePositionInGrid(new MatrixI(newBlock.BlockOrientation), mirrorDefinition, newBlock.Min);

                // Don't place a block if one already exists there in the mirror.
                if (integrate && cubeBlocks.Any(b => b.Position.X == newPosition.X && b.Position.Y == newPosition.Y && b.Position.Z == newPosition.Z))
                {
                    continue;
                }

                //VRage.Utils.MyLog.Default.WriteLineAndConsole($"## CHECK ## new block {newBlock.SubtypeName}");

                blocks.Add(newBlock);

                // Alternate to using AddBlock().
                //Quaternion q;
                //((MyBlockOrientation)newBlock.BlockOrientation).GetQuaternion(out q);
                //((MyCubeGrid)shipEntity).BuildGeneratedBlock(new MyCubeGrid.MyBlockLocation(mirrorDefinition.Id, newBlock.Min, newBlock.Min, newBlock.Min, q, 0, 0) , newBlock.ColorMaskHSV);
            }
            return(blocks);
        }