public override void OnChunkDiscarding(TerrainChunk chunk) { BoundingBox boundingBox = new BoundingBox(chunk.BoundingBox.Min - new Vector3(16f), chunk.BoundingBox.Max + new Vector3(16f)); DynamicArray <IMovingBlockSet> dynamicArray = new DynamicArray <IMovingBlockSet>(); m_subsystemMovingBlocks.FindMovingBlocks(boundingBox, extendToFillCells: false, dynamicArray); foreach (IMovingBlockSet item in dynamicArray) { if (item.Id == "Piston") { StopPiston((Point3)item.Tag); } } }
public void FindMovingBlocksCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result) { Vector3 boxSize = BoxSize; BoundingBox boundingBox = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f)); boundingBox.Min -= new Vector3(1f); boundingBox.Max += new Vector3(1f); m_movingBlockSets.Clear(); m_subsystemMovingBlocks.FindMovingBlocks(boundingBox, extendToFillCells: false, m_movingBlockSets); for (int i = 0; i < m_movingBlockSets.Count; i++) { IMovingBlockSet movingBlockSet = m_movingBlockSets.Array[i]; for (int j = 0; j < movingBlockSet.Blocks.Count; j++) { MovingBlock movingBlock = movingBlockSet.Blocks[j]; int num = Terrain.ExtractContents(movingBlock.Value); Block block = BlocksManager.Blocks[num]; if (block.IsCollidable) { BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, movingBlock.Value); Vector3 v = new Vector3(movingBlock.Offset) + movingBlockSet.Position; for (int k = 0; k < customCollisionBoxes.Length; k++) { result.Add(new CollisionBox { Box = new BoundingBox(v + customCollisionBoxes[k].Min, v + customCollisionBoxes[k].Max), BlockValue = movingBlock.Value, BlockVelocity = movingBlockSet.CurrentVelocity }); } } } } }