/// <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); } }
/// <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)); IEnumerable <Block> blocks = null; if (_schematic.Blocks.Count > 0) { BlockGlobal firstBlock = _firstBlockInEachRegion[index]; //blocks = _schematic.Blocks.Where(block => block.X >= firstBlock.X && block.Y >= firstBlock.Y && block.Z >= firstBlock.Z && block.X < firstBlock.X + CHUNK_SIZE && block.Y < firstBlock.Y + CHUNK_SIZE && block.Z < firstBlock.Z + CHUNK_SIZE); blocks = GetBlocksInRegion(new Vector3(firstBlock.X, firstBlock.Y, firstBlock.Z), new Vector3(firstBlock.X + CHUNK_SIZE, firstBlock.Y + CHUNK_SIZE, firstBlock.Z + CHUNK_SIZE)); } 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 % CHUNK_SIZE)); writer.Write((byte)(block.Y % CHUNK_SIZE)); writer.Write((byte)(block.Z % CHUNK_SIZE)); if (block.PalettePosition != -1) { writer.Write((byte)(block.PalettePosition + 1)); } else { int i = _usedColors.IndexOf(block.Color.UIntToColor()) + 1; writer.Write((i != 0) ? (byte)i : (byte)1); } //_schematic.Blocks.Remove(block); } }
/// <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); } }