private void MyShipMergeBlock_IsWorkingChanged(MyCubeBlock obj) { Debug.Assert(Physics != null || !InScene); if (Physics != null) { Physics.Enabled = this.IsWorking; } if (!this.IsWorking) { var otherBlock = GetOtherMergeBlock(); if (otherBlock != null) { } else if (InConstraint) { RemoveConstraintInBoth(); } } CheckConnectionAllowed = !this.IsWorking; CubeGrid.UpdateBlockNeighbours(this.SlimBlock); CheckEmissivity(); }
public bool Remove(ushort blockId, bool removeFromScene = true) { MySlimBlock block; if (m_blocks.TryGetValue(blockId, out block)) { m_blocks.Remove(blockId); if (removeFromScene) { block.FatBlock.OnRemovedFromScene(this); block.FatBlock.Close(); } if (block.FatBlock.Hierarchy.Parent == Hierarchy) { block.FatBlock.Hierarchy.Parent = null; } CubeGrid.UpdateBlockNeighbours(SlimBlock); RefreshTemplates(); return(true); } Debug.Fail("Cannot remove block from compound"); return(false); }
/// <summary> /// Adds block to compound (should be used for clients). /// </summary> /// <returns>true if the block has been addded, otherwise false</returns> public bool Add(ushort id, MySlimBlock block) { if (!CanAddBlock(block)) { return(false); } Debug.Assert(block.BlockDefinition.Size == Vector3I.One, "Only blocks with size=1 are supported inside compound block!"); Debug.Assert(block.BlockDefinition.CubeSize == MyCubeSize.Large, "Only large blocks are supported inside compound block!"); if (m_mapIdToBlock.ContainsKey(id)) { Debug.Fail("Cannot add block with existing id to compound block!"); return(false); } m_mapIdToBlock.Add(id, block); m_blocks.Add(block); Debug.Assert(m_mapIdToBlock.Count == m_blocks.Count); MatrixD parentWorldMatrix = this.Parent.WorldMatrix; MatrixD blockLocalMatrix = MatrixD.Identity; GetBlockLocalMatrixFromGridPositionAndOrientation(block, ref blockLocalMatrix); MatrixD worldMatrix = blockLocalMatrix * parentWorldMatrix; block.FatBlock.PositionComp.SetWorldMatrix(worldMatrix, this, true); // Set parent before OnAddedToScene otherwise chhild block will be added to pruning structure block.FatBlock.Hierarchy.Parent = Hierarchy; block.FatBlock.OnAddedToScene(this); CubeGrid.UpdateBlockNeighbours(SlimBlock); RefreshTemplates(); if (block.IsMultiBlockPart) { CubeGrid.AddMultiBlockInfo(block); } return(true); }
public bool Remove(ushort blockId, bool merged = false) { MySlimBlock block; if (m_mapIdToBlock.TryGetValue(blockId, out block)) { m_mapIdToBlock.Remove(blockId); m_blocks.Remove(block); Debug.Assert(m_mapIdToBlock.Count == m_blocks.Count); if (!merged) { if (block.IsMultiBlockPart) { CubeGrid.RemoveMultiBlockInfo(block); } block.FatBlock.OnRemovedFromScene(this); block.FatBlock.Close(); } if (block.FatBlock.Hierarchy.Parent == Hierarchy) { block.FatBlock.Hierarchy.Parent = null; } if (!merged) { CubeGrid.UpdateBlockNeighbours(SlimBlock); } RefreshTemplates(); return(true); } Debug.Fail("Cannot remove block from compound"); return(false); }
/// <summary> /// Adds block to compound (should be used for clients). /// </summary> /// <returns>true if the block has been addded, otherwise false</returns> public bool Add(ushort id, MySlimBlock block) { if (!CanAddBlock(block)) { return(false); } // block.AddNeighbours(); Debug.Assert(block.BlockDefinition.Size == Vector3I.One, "Only blocks with size=1 are supported!"); if (m_blocks.ContainsKey(id)) { Debug.Fail("Cannot add block with existing id to compound block!"); return(false); } m_blocks.Add(id, block); MatrixD parentWorldMatrix = this.Parent.WorldMatrix; MatrixD blockLocalMatrix = MatrixD.Identity; GetBlockLocalMatrixFromGridPositionAndOrientation(block, ref blockLocalMatrix); MatrixD worldMatrix = blockLocalMatrix * parentWorldMatrix; block.FatBlock.PositionComp.SetWorldMatrix(worldMatrix, this, true); block.FatBlock.OnAddedToScene(this); block.FatBlock.Hierarchy.Parent = Hierarchy; CubeGrid.UpdateBlockNeighbours(SlimBlock); RefreshTemplates(); return(true); }