protected bool TestGridPlacementOnGrid(MyCubeGrid previewGrid, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { bool retval = true; Vector3I gridOffset = hitGrid.WorldToGridInteger(m_pastePosition); MatrixI transform = hitGrid.CalculateMergeTransform(previewGrid, gridOffset); if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE) { MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 60.0f), "First grid offset: " + gridOffset.ToString(), Color.Red, 1.0f); } retval = retval && hitGrid.GridSizeEnum == previewGrid.GridSizeEnum && hitGrid.CanMergeCubes(previewGrid, gridOffset); retval = retval && MyCubeGrid.CheckMergeConnectivity(hitGrid, previewGrid, gridOffset); // Check if any block connects to hit grid if (retval) { bool connected = false; foreach (var block in previewGrid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { connected |= CheckConnectivityOnGrid(blockInCompound, ref transform, ref settings, hitGrid); if (connected) { break; } } } else { connected |= CheckConnectivityOnGrid(block, ref transform, ref settings, hitGrid); } if (connected) { break; } } retval &= connected; } if (retval) { foreach (var block in previewGrid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { retval = retval && TestBlockPlacementOnGrid(blockInCompound, ref transform, ref settings, hitGrid); if (!retval) { break; } } } else { retval = retval && TestBlockPlacementOnGrid(block, ref transform, ref settings, hitGrid); } if (!retval) { break; } } } return(retval); }