Exemple #1
0
        public virtual byte[] GetValue()
        {
            byte[] result;

              using (MemoryStream stream = new MemoryStream())
              {
            TagWriter writer;

            writer = new BinaryTagWriter(stream, NbtOptions.ReadHeader);
            writer.Write(this);

            result = stream.ToArray();
              }

              return result;
        }
        private void WriteSchematic(CarbonFile targetFile)
        {
            var sizeVector = this.outputBoundingBox.Maximum - this.outputBoundingBox.Minimum + new Vector3(1);
            int maxAddress = (int)(sizeVector.Y * sizeVector.Z * sizeVector.X);
            using (var file = File.Open(targetFile.GetPath(), FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                var writer = new BinaryTagWriter(file);
                var compound = new TagCompound("Schematic");
                compound.Value.Add(new TagShort("Height", (short)sizeVector.Y));
                compound.Value.Add(new TagShort("Length", (short)sizeVector.Z));
                compound.Value.Add(new TagShort("Width", (short)sizeVector.X));
                compound.Value.Add(new TagList("Entities"));
                compound.Value.Add(new TagList("TileEntities"));
                compound.Value.Add(new TagString("Materials", "Alpha"));

                var blockArray = new byte[maxAddress];
                var biomeArray = new byte[(int)(sizeVector.Z * sizeVector.X)];
                var dataArray = new byte[maxAddress];

                foreach (Block block in this.blocks.Keys)
                {
                    // (Y×length + Z)×width + X
                    int address = this.GetInternalAddress(sizeVector, new Vector3(block.X, block.Y, block.Z));
                    blockArray[address] = 41; // Gold block for testing
                    dataArray[address] = 0;
                }

                /*int count = 0;
                for (var x = 0; x < sizeVector.X; x++)
                {
                    for (var y = 0; y < sizeVector.Y; y++)
                    {
                        for (var z = 0; z < sizeVector.Z; z++)
                        {
                            int test = this.GetInternalAddress(sizeVector, new Vector3(x, y, z));
                            blockArray[test] = 23;
                            count++;
                        }
                    }
                }*/

                /*for (int i = 0; i < sizeVector.Y; i++)
                {
                    //blockArray[i] = 1;
                    int test = this.GetInternalAddress(sizeVector, new Vector3(i, i, i));
                    blockArray[test] = 1;
                }*/

                compound.Value.Add(new TagByteArray("Data", dataArray));
                compound.Value.Add(new TagByteArray("Biomes", biomeArray));
                compound.Value.Add(new TagByteArray("Blocks", blockArray));
                writer.Write(compound);
            }
        }