Beispiel #1
0
        /// <summary>
        /// Gets the block list index of the given block position.
        /// </summary>
        /// <param name="pos">The block position.</param>
        /// <returns>The block index.</returns>
        private int BlockIndex(BlockPosition pos)
        {
            if (IsCorners(pos) || IsOutOfBounds(pos))
            {
                throw new System.ArgumentException("Block position out of range!", "pos");
            }

            int j = GetChunkSide(pos);

            if (j == -1)
            {
                return(pos.Index(ChunkSize));
            }

            return(GetNextBlock(pos, j));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the index of the neighbor block based on the given block position and chunk edge.
        /// </summary>
        /// <param name="pos">The block position.</param>
        /// <param name="j">The chunk edge.</param>
        /// <returns>The block index.</returns>
        private int GetNextBlock(BlockPosition pos, int j)
        {
            switch (j)
            {
            case 0:
            case 1:
                pos = new BlockPosition(j, pos.Y, pos.Z);
                break;

            case 2:
            case 3:
                pos = new BlockPosition(j, pos.X, pos.Z);
                break;

            case 4:
            case 5:
                pos = new BlockPosition(j, pos.X, pos.Y);
                break;
            }

            return(pos.Index(ChunkSize) + ChunkSize.Volume);
        }
Beispiel #3
0
 /// <summary>
 /// Sets the block ID at the given local block position within the container.
 /// </summary>
 /// <param name="pos">The local block position.</param>
 /// <param name="id">The block ID to assign.</param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// If the block position is not within the container.
 /// </exception>
 public void SetBlockID(BlockPosition pos, ushort id) => m_Blocks[pos.Index(Size)] = id;
Beispiel #4
0
 /// <summary>
 /// Gets the block ID at the given local block position within the container.
 /// </summary>
 /// <param name="pos">The local block position.</param>
 /// <returns>The block ID.</returns>
 /// <exception cref="ArgumentOutOfRangeException">
 /// If the block position is not within the container.
 /// </exception>
 public ushort GetBlockID(BlockPosition pos) => m_Blocks[pos.Index(Size)];