示例#1
0
        public byte[] ToBytes()
        {
            List <byte> buffer = new List <byte>();

            buffer.AddRange(BitConverter.GetBytes(NonEmptyBlocks));
            if (NonEmptyBlocks > 0)
            {
                int       sameBlockCount = 1;
                BlockData lastBlockData  = blocks[0];

                for (int index = 1; index < Env.ChunkSizeWithPaddingPow3; index++)
                {
                    BlockData blockData = blocks[index];
                    if (blockData.Equals(lastBlockData))
                    {
                        // If this is the same as the last block added increase the count
                        ++sameBlockCount;
                    }
                    else
                    {
                        buffer.AddRange(BitConverter.GetBytes(sameBlockCount));
                        buffer.AddRange(BlockData.ToByteArray(lastBlockData));

                        sameBlockCount = 1;
                        lastBlockData  = blockData;
                    }
                }

                buffer.AddRange(BitConverter.GetBytes(sameBlockCount));
                buffer.AddRange(BlockData.ToByteArray(lastBlockData));
            }

            return(buffer.ToArray());
        }
示例#2
0
文件: Chunk.cs 项目: bejita968/Voxe
        /// <summary>
        ///     Changes a given block to a block of a different type
        /// </summary>
        public void ModifyBlock(int x, int y, int z, BlockData blockData)
        {
            int index = Helpers.GetIndex1DFrom3D(x, y, z);

            // Nothing for us to do if block did not change
            BlockData thisBlock = this[x, y, z];

            if (blockData.Equals(thisBlock))
            {
                return;
            }

            m_setBlockQueue.Add(new SetBlockContext(index, blockData, true));
        }
示例#3
0
 public bool Equals(SetBlockContext other)
 {
     return(Index == other.Index && Block.Equals(other.Block));
 }
示例#4
0
 public bool Equals(SetBlockContext other)
 {
     return(IndexFrom == other.IndexFrom && IndexTo == other.IndexTo && Block.Equals(other.Block));
 }