Example #1
0
        /// <summary>
        /// Write XYZI chunk
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="index"></param>
        private void WriteXyziChunk(BinaryWriter writer, int index)
        {
            writer.Write(Encoding.UTF8.GetBytes(XYZI));
            HashSet <Block> blocks = new HashSet <Block>();

            if (_schematic.Blocks.Count > 0)
            {
                BlockGlobal firstBlock = _firstBlockInEachRegion[index];
                blocks = GetBlocksInRegion(new Vector3(firstBlock.X, firstBlock.Y, firstBlock.Z), new Vector3(firstBlock.X + 126, firstBlock.Y + 126, firstBlock.Z + 126));
            }
            writer.Write((blocks.Count() * 4) + 4); //XYZI chunk size
            writer.Write(0);                        //Child chunk size (constant)
            writer.Write(blocks.Count());           //Blocks count
            _countBlocks += blocks.Count;

            foreach (Block block in blocks)
            {
                writer.Write((byte)(block.X % 126));
                writer.Write((byte)(block.Y % 126));
                writer.Write((byte)(block.Z % 126));
                int i = _usedColors.IndexOf(block.Color.UIntToColor()) + 1;
                writer.Write((i != 0) ? (byte)i : (byte)1);
                _schematic.Blocks.Remove(block);
            }
        }
Example #2
0
        /// <summary>
        /// Get world coordinates of the first block in each region
        /// </summary>
        private void GetFirstBlockForEachRegion()
        {
            _firstBlockInEachRegion = new BlockGlobal[_countSize];
            int min = 0;

            if (_direction == 0)
            {
                min = (_width < _length) ? _width : _length;
            }
            else
            {
                min = (_width > _length) ? _width : _length;
            }

            for (int i = 0; i < _countSize; i++)
            {
                int x = (i / (min * _height) * 126);
                int y = (((i / min) % _height) * 126);
                int z = ((i % min) * 126);
                _firstBlockInEachRegion[i] = new BlockGlobal(x, y, z);
            }
        }