private void BuildBlock(IMySlimBlock block, MyCubeBlock constructionBlock) { MyObjectBuilder_CubeBlock cubeBlock = block.GetObjectBuilder(); MyObjectBuilder_ProjectorBase projectorBuilder = null;// = (MyObjectBuilder_ProjectorBase)constructionBlock.GetObjectBuilderCubeBlock(); MyCubeGrid projectorGrid = null; MyCubeGrid blockGrid = (MyCubeGrid)block.CubeGrid; MyCubeBlock projector = null; foreach (var item in NaniteConstructionManager.ProjectorBlocks) { var projectorTest = item.Value as IMyProjector; if (projectorTest == null) { continue; } if (projectorTest.ProjectedGrid == null) { continue; } if (projectorTest.ProjectedGrid == block.CubeGrid) { projector = (MyCubeBlock)projectorTest; projectorGrid = projector.CubeGrid; projectorBuilder = (MyObjectBuilder_ProjectorBase)projector.GetObjectBuilderCubeBlock(); break; } } /* * Ingame.IMyGridTerminalSystem system = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid); * List<Ingame.IMyTerminalBlock> terminalBlocks = new List<Ingame.IMyTerminalBlock>(); * system.GetBlocks(terminalBlocks); * foreach(var item in terminalBlocks) * { * if (!(item is IMyFunctionalBlock) || !((IMyFunctionalBlock)item).Enabled) * continue; * * if (!(item is Ingame.IMyProjector)) * continue; * * var cube = (MyCubeBlock)item; * MyObjectBuilder_ProjectorBase testBuilder = (MyObjectBuilder_ProjectorBase)cube.GetObjectBuilderCubeBlock(); * if (testBuilder.ProjectedGrid == null) * continue; * * if(testBuilder.ProjectedGrid.DisplayName == blockGrid.DisplayName) * { * projector = cube; * projectorGrid = cube.CubeGrid; * projectorBuilder = testBuilder; * break; * } * } */ if (projectorBuilder == null) { Logging.Instance.WriteLine("PROBLEM Can not locate projector that is projecting target!"); return; } Quaternion quat = Quaternion.Identity; var orientation = block.Orientation; Matrix local; orientation.GetMatrix(out local); var gridOrientation = GetGridOrientation(projectorBuilder); if (gridOrientation != Matrix.Identity) { var afterRotation = Matrix.Multiply(local, gridOrientation); orientation = new MyBlockOrientation(ref afterRotation); } Quaternion projQuat = Quaternion.Identity; projector.Orientation.GetQuaternion(out projQuat); orientation.GetQuaternion(out quat); quat = Quaternion.Multiply(projQuat, quat); // Get real block max MyCubeBlockDefinition blockDefinition = (MyCubeBlockDefinition)block.BlockDefinition; Vector3I blockMax = block.Max; Vector3I blockMin = cubeBlock.Min; Vector3I position = block.Position; Vector3I min = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMin)); Vector3I max = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax)); Vector3I pos = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Position)); Vector3I projectedMin = new Vector3I(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y), Math.Min(min.Z, max.Z)); Vector3I projectedMax = new Vector3I(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y), Math.Max(min.Z, max.Z)); MyCubeGrid.MyBlockLocation location = new MyCubeGrid.MyBlockLocation(blockDefinition.Id, projectedMin, projectedMax, pos, quat, 0, constructionBlock.OwnerId); /* * MyObjectBuilder_CubeGrid originalGridBuilder = (MyObjectBuilder_CubeGrid)blockGrid.GetObjectBuilder(); * MyObjectBuilder_CubeBlock objectBuilder = null; * //Find original grid builder * foreach (var blockBuilder in originalGridBuilder.CubeBlocks) * { * if (blockBuilder.GetId() == blockDefinition.Id) * { * if ((Vector3I)blockBuilder.Min == blockMin) * { * objectBuilder = (MyObjectBuilder_CubeBlock)blockBuilder.Clone(); * objectBuilder.SetupForProjector(); * } * } * } */ MyObjectBuilder_CubeBlock objectBuilder = cubeBlock; objectBuilder.SetupForProjector(); var functionalBuilder = objectBuilder as MyObjectBuilder_FunctionalBlock; if (functionalBuilder != null && !functionalBuilder.Enabled) { functionalBuilder.Enabled = true; } var terminalBuilder = objectBuilder as MyObjectBuilder_TerminalBlock; if (terminalBuilder != null) { terminalBuilder.Owner = constructionBlock.OwnerId; } var shipConnector = objectBuilder as MyObjectBuilder_ShipConnector; if (shipConnector != null) { shipConnector.Connected = false; shipConnector.ConnectedEntityId = 0; shipConnector.MasterToSlaveGrid = null; shipConnector.MasterToSlaveTransform = null; } //if (objectBuilder == null) // objectBuilder = cubeBlock; location.EntityId = 0; // MyEntityIdentifier.AllocateId(); objectBuilder.EntityId = 0; objectBuilder.ConstructionInventory = null; projector.CubeGrid.BuildBlockRequest(block.GetColorMask().PackHSVToUint(), location, objectBuilder, constructionBlock.EntityId, false, constructionBlock.OwnerId); }