示例#1
0
        /// <summary>
        /// Determines whether a block at the specified position with the specified
        /// connection sides can connect to any other block.
        /// </summary>
        private bool CanConnect(BlockPosition position, BlockSides rotatedConnectSides)
        {
            for (int bit = 0; bit < 6; bit++)
            {
                BlockSides side = rotatedConnectSides & (BlockSides)(1 << bit);
                if (side == BlockSides.None ||
                    !position.GetOffseted(side, out BlockPosition offseted) ||
                    !_blocks.TryGetValue(offseted, out IPlacedBlock block))
                {
                    continue;
                }

                int inverseBit = bit % 2 == 0 ? bit + 1 : bit - 1;
                if ((block.ConnectSides & (BlockSides)(1 << inverseBit)) != BlockSides.None)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// Gets the positions of all parts in the multi blocks relative to the specified origin.
        /// Both the positions are and the connection points are rotated.
        /// Returns false if any of these positions is out of bounds.
        /// </summary>
        // ReSharper disable once AnnotateCanBeNullParameter
        public bool GetRotatedPositions(BlockPosition origin, byte rotation, out KeyValuePair <BlockPosition, BlockSides>[] output)
        {
            output = new KeyValuePair <BlockPosition, BlockSides> [_partConnectSides.Count];
            Quaternion rotationQuaternion = Rotation.GetQuaternion(rotation);

            for (int index = 0; index < _partConnectSides.Count; index++)
            {
                KeyValuePair <Vector3Int, BlockSides> pair = _partConnectSides[index];
                Vector3Int offset = Vector3Int.RoundToInt(rotationQuaternion * pair.Key);

                if (!origin.GetOffseted(offset.x, offset.y, offset.z, out BlockPosition position))
                {
                    output = null;
                    return(false);
                }

                output[index] = new KeyValuePair <BlockPosition, BlockSides>(position, Rotation.RotateSides(pair.Value, rotation));
            }
            return(true);
        }