Example #1
0
        public void WriteChunk(Chunk chunk, string path)
        {
            try {
                using (FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) {
                    using (GZipStream wrapper = new GZipStream(fs, CompressionMode.Compress)) {
                        BinaryWriter writer = new BinaryWriter(wrapper);
                        NbtFile      nbt    = new NbtFile(writer);

                        nbt.Write(NbtTagType.Compound);
                        nbt.Write("");

                        nbt.Write(NbtTagType.Compound);
                        nbt.Write("Level");

                        nbt.Write(NbtTagType.Int8);
                        nbt.Write("TerrainPopulated"); nbt.WriteUInt8((byte)1);

                        nbt.Write(NbtTagType.Int8Array);
                        nbt.Write("Blocks"); nbt.WriteInt32(chunk.blocks.Length);
                        nbt.WriteBytes(chunk.blocks);

                        nbt.Write(NbtTagType.Int8Array);
                        nbt.Write("Data"); nbt.WriteInt32(chunk.metadata.Data.Length);
                        nbt.WriteBytes(chunk.metadata.Data);

                        nbt.Write(NbtTagType.End);

                        nbt.Write(NbtTagType.End);
                    }
                }
            } catch (Exception ex) {
                ErrorHandler.LogError("saving chunk", ex);
                game.Chat.Add("Failed to save chunk.");
            }
        }
        public void Save(Stream stream, Game game)
        {
            using (GZipStream wrapper = new GZipStream(stream, CompressionMode.Compress)) {
                writer    = new BinaryWriter(wrapper);
                nbt       = new NbtFile(writer);
                this.game = game;
                map       = game.World;

                nbt.Write(NbtTagType.Compound); nbt.Write("ClassicWorld");

                nbt.Write(NbtTagType.Int8);
                nbt.Write("FormatVersion"); nbt.WriteInt8(1);

                nbt.Write(NbtTagType.Int8Array);
                nbt.Write("UUID"); nbt.WriteInt32(16);
                nbt.WriteBytes(map.Uuid.ToByteArray());

                nbt.Write(NbtTagType.Int16);
                nbt.Write("X"); nbt.WriteInt16((short)map.Width);

                nbt.Write(NbtTagType.Int16);
                nbt.Write("Y"); nbt.WriteInt16((short)map.Height);

                nbt.Write(NbtTagType.Int16);
                nbt.Write("Z"); nbt.WriteInt16((short)map.Length);

                WriteSpawnCompoundTag();

                nbt.Write(NbtTagType.Int8Array);
                nbt.Write("BlockArray"); nbt.WriteInt32(map.blocks.Length);
                                #if USE16_BIT
                nbt.WriteBytes(Utils.UInt16sToUInt8s(map.blocks));
                                #else
                nbt.WriteBytes(map.blocks);
                                #endif

                WriteMetadata();

                nbt.Write(NbtTagType.End);
            }
        }
        void WriteBlocks( NbtFile nbt, byte[] blocks )
        {
            const int chunkSize = 64 * 1024 * 32;
            nbt.Write( NbtTagType.Int8Array );
            nbt.Write( "Blocks" );
            nbt.WriteInt32( blocks.Length );

            for( int i = 0; i < blocks.Length; i += chunkSize ) {
                int count = Math.Min( chunkSize, blocks.Length - i );
                nbt.WriteBytes( blocks, i, count );
            }
        }
Example #4
0
        void WriteBlocks(NbtFile nbt, byte[] blocks)
        {
            const int chunkSize = 64 * 1024 * 32;

            nbt.Write(NbtTagType.Int8Array, "Blocks");
            nbt.WriteInt32(blocks.Length);

            for (int i = 0; i < blocks.Length; i += chunkSize)
            {
                int count = Math.Min(chunkSize, blocks.Length - i);
                nbt.WriteBytes(blocks, i, count);
            }
        }
        void WriteBlockData( NbtFile nbt, byte[] blocks )
        {
            const int chunkSize = 64 * 1024;
            byte[] chunk = new byte[chunkSize];
            nbt.Write( NbtTagType.Int8Array );
            nbt.Write( "Data" );
            nbt.WriteInt32( blocks.Length );

            for( int i = 0; i < blocks.Length; i += chunkSize ) {
                // All 0 so we can skip this.
                int count = Math.Min( chunkSize, blocks.Length - i );
                nbt.WriteBytes( chunk, 0, count );
            }
        }
Example #6
0
        public void Save( Stream stream, Game game )
        {
            using( GZipStream wrapper = new GZipStream( stream, CompressionMode.Compress ) ) {
                writer = new BinaryWriter( wrapper );
                nbt = new NbtFile( writer );
                this.game = game;
                map = game.World;

                nbt.Write( NbtTagType.Compound ); nbt.Write( "ClassicWorld" );

                nbt.Write( NbtTagType.Int8 );
                nbt.Write( "FormatVersion" ); nbt.WriteInt8( 1 );

                nbt.Write( NbtTagType.Int8Array );
                nbt.Write( "UUID" ); nbt.WriteInt32( 16 );
                nbt.WriteBytes( map.Uuid.ToByteArray() );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "X" ); nbt.WriteInt16( (short)map.Width );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "Y" ); nbt.WriteInt16( (short)map.Height );

                nbt.Write( NbtTagType.Int16 );
                nbt.Write( "Z" ); nbt.WriteInt16( (short)map.Length );

                WriteSpawnCompoundTag();

                nbt.Write( NbtTagType.Int8Array );
                nbt.Write( "BlockArray" ); nbt.WriteInt32( map.blocks.Length );
                nbt.WriteBytes( map.blocks );

                WriteMetadata();

                nbt.Write( NbtTagType.End );
            }
        }
Example #7
0
        public void Save(Stream stream, Game game)
        {
            using (GZipStream s = new GZipStream(stream, CompressionMode.Compress)) {
                writer    = new BinaryWriter(s);
                nbt       = new NbtFile(writer);
                this.game = game;
                map       = game.World;

                nbt.Write(NbtTagType.Compound, "ClassicWorld");

                nbt.Write(NbtTagType.Int8, "FormatVersion");
                nbt.WriteUInt8(1);

                nbt.Write(NbtTagType.Int8Array, "UUID");
                nbt.WriteInt32(16);
                nbt.WriteBytes(map.Uuid.ToByteArray());

                nbt.Write(NbtTagType.Int16, "X");
                nbt.WriteInt16((short)map.Width);

                nbt.Write(NbtTagType.Int16, "Y");
                nbt.WriteInt16((short)map.Height);

                nbt.Write(NbtTagType.Int16, "Z");
                nbt.WriteInt16((short)map.Length);

                WriteSpawnCompoundTag();

                nbt.Write(NbtTagType.Int8Array, "BlockArray");
                nbt.WriteInt32(map.blocks.Length);
                nbt.WriteBytes(map.blocks);

                WriteMetadata();

                nbt.Write(NbtTagType.End);
            }
        }
Example #8
0
        void WriteBlockData(NbtFile nbt, int blocksLength)
        {
            const int chunkSize = 64 * 1024;

            byte[] chunk = new byte[chunkSize];
            nbt.Write(NbtTagType.Int8Array, "Data");
            nbt.WriteInt32(blocksLength);

            for (int i = 0; i < blocksLength; i += chunkSize)
            {
                // All 0 so we can skip this.
                int count = Math.Min(chunkSize, blocksLength - i);
                nbt.WriteBytes(chunk, 0, count);
            }
        }