예제 #1
0
 internal override void WriteData(NbtBinaryWriter writeStream)
 {
     writeStream.Write(Value.Length);
     for (int i = 0; i < Value.Length; i++)
     {
         writeStream.Write(Value[i]);
     }
 }
예제 #2
0
 internal override void WriteTag(NbtBinaryWriter writeStream)
 {
     writeStream.Write(NbtTagType.Short);
     if (Name == null)
     {
         throw new NbtFormatException("Name is null");
     }
     writeStream.Write(Name);
     writeStream.Write(Value);
 }
예제 #3
0
 internal override void WriteTag(NbtBinaryWriter writeStream)
 {
     writeStream.Write(NbtTagType.IntArray);
     if (Name == null)
     {
         throw new NbtFormatException("Name is null");
     }
     writeStream.Write(Name);
     WriteData(writeStream);
 }
예제 #4
0
        private byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            MemoryStream stream = new MemoryStream();
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                writer.Write(blocks);
                writer.Write(metadata.Data);
                writer.Write(skylight.Data);
                writer.Write(blocklight.Data);

                //RecalcHeight();
                writer.Write(height);

                for (int i = 0; i < biomeColor.Length; i++)
                {
                    writer.Write(biomeColor[i]);
                }

                int extraSize = 0;
                writer.Write(extraSize);                 // No extra data

                if (BlockEntities.Count == 0)
                {
                    NbtFile file = new NbtFile(new NbtCompound(string.Empty))
                    {
                        BigEndian = false
                    };
                    writer.Write(file.SaveToBuffer(NbtCompression.None));
                }
                else
                {
                    foreach (NbtCompound blockEntity in BlockEntities.Values.ToArray())
                    {
                        NbtFile file = new NbtFile(blockEntity)
                        {
                            BigEndian = false
                        };
                        writer.Write(file.SaveToBuffer(NbtCompression.None));
                    }
                }


                writer.Flush();
                writer.Close();
            }

            var bytes = stream.ToArray();

            stream.Close();

            _cache = bytes;

            return(bytes);
        }
예제 #5
0
 internal override void WriteData(NbtBinaryWriter writeStream)
 {
     if (ListType == NbtTagType.Unknown)
     {
         throw new NbtFormatException("NbtList had no elements and an Unknown ListType");
     }
     writeStream.Write(ListType);
     writeStream.Write(tags.Count);
     foreach (NbtTag tag in tags)
     {
         tag.WriteData(writeStream);
     }
 }
예제 #6
0
        internal override void WriteTag(NbtBinaryWriter writeStream, bool writeName)
        {
            writeStream.Write(NbtTagType.Double);
            if (writeName)
            {
                if (Name == null)
                {
                    throw new NbtFormatException("Name is null");
                }
                writeStream.Write(Name);
            }

            writeStream.Write(Value);
        }
예제 #7
0
 public byte[] Export()
 {
     byte[] buffer;
     using (var stream = new MemoryStream())
     {
         var writer = new NbtBinaryWriter(stream, false);
         writer.Write(Health);
         writer.Write(Air);
         writer.Write(FireTick);
         writer.Write(IsOnFire);
         buffer = stream.GetBuffer();
     }
     return(buffer);
 }
예제 #8
0
        public byte[] GetBytes(bool compress)
        {
            if (compress)
            {
                return(GetBytes());
            }

            MemoryStream    stream = new MemoryStream();
            NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

            writer.Write(IPAddress.HostToNetworkOrder(x));
            writer.Write(IPAddress.HostToNetworkOrder(z));

            writer.Write(blocks);
            writer.Write(metadata.Data);
            writer.Write(skylight.Data);
            writer.Write(blocklight.Data);

            writer.Write(biomeId);

            for (int i = 0; i < biomeColor.Length; i++)
            {
                writer.Write(biomeColor[i]);
            }


            writer.Flush();

            writer.Close();
            return(stream.ToArray());
        }
예제 #9
0
        public byte[] GetBytes()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new NbtBinaryWriter(stream, true))
                {
                    writer.Write(IPAddress.HostToNetworkOrder(X));
                    writer.Write(IPAddress.HostToNetworkOrder(Y));
                    writer.Write(true);
                    writer.Write((ushort)0xffff); // bitmap
                    writer.WriteVarInt(Blocks.Length + Skylight.Length + 33024 + 32768);

                    writer.Write(Blocks);

                    writer.Write(Blocklight);
                    writer.Write(Skylight);

                    writer.Write(BiomeId); //OK

                    writer.Flush();
                    writer.Close();
                }
                return(stream.ToArray());
            }
        }
예제 #10
0
        public byte[] GetMeta()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new NbtBinaryWriter(stream, true))
                {
                    writer.Write(IPAddress.HostToNetworkOrder(X));
                    writer.Write(IPAddress.HostToNetworkOrder(Z));
                    writer.Write((ushort)0xffff);                      // bitmap

                    writer.Flush();
                    writer.Close();
                }
                return(stream.ToArray());
            }
        }
예제 #11
0
        public byte[] CompressBytes(byte[] input)
        {
            MemoryStream stream = new MemoryStream();

            stream.WriteByte(0x78);
            stream.WriteByte(0x01);
            int checksum;

            using (var compressStream = new ZLibStream(stream, CompressionLevel.Optimal, true))
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(compressStream, true);
                writer.Write(input);

                writer.Flush();

                checksum = compressStream.Checksum;
                writer.Close();
            }

            byte[] checksumBytes = BitConverter.GetBytes(checksum);
            if (BitConverter.IsLittleEndian)
            {
                // Adler32 checksum is big-endian
                Array.Reverse(checksumBytes);
            }
            stream.Write(checksumBytes, 0, checksumBytes.Length);

            var bytes = stream.ToArray();

            stream.Close();

            return(bytes);
        }
예제 #12
0
 internal override void WriteData(NbtBinaryWriter writeStream)
 {
     foreach (NbtTag tag in tags.Values)
     {
         tag.WriteTag(writeStream);
     }
     writeStream.Write(NbtTagType.End);
 }
예제 #13
0
        public byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            using (MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream())
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                writer.Write(blocks);
                writer.Write(metadata.Data);
                _cache = stream.ToArray();
            }

            return(_cache);
        }
예제 #14
0
        public byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            using (MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream())
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                writer.Write(blocks);
                writer.Write(metadata.Data);
                writer.Write(skylight.Data);
                writer.Write(blocklight.Data);

                //RecalcHeight();
                writer.Write(height);

                BiomeUtils utils = new BiomeUtils();
                utils.PrecomputeBiomeColors();

                InterpolateBiomes();

                for (int i = 0; i < biomeId.Length; i++)
                {
                    var biome = biomeId[i];
                    int color = biomeColor[i];
                    writer.Write((color & 0x00ffffff) | biome << 24);
                }

                short extraSize = 0;
                writer.Write(extraSize);                 // No extra data

                if (BlockEntities.Count == 0)
                {
                    //NbtFile file = new NbtFile(new NbtCompound(string.Empty)) {BigEndian = false, UseVarInt = true};
                    //file.SaveToStream(writer.BaseStream, NbtCompression.None);
                }
                else
                {
                    foreach (NbtCompound blockEntity in BlockEntities.Values.ToArray())
                    {
                        NbtFile file = new NbtFile(blockEntity)
                        {
                            BigEndian = false, UseVarInt = true
                        };
                        file.SaveToStream(writer.BaseStream, NbtCompression.None);
                    }
                }

                _cache = stream.ToArray();
            }

            return(_cache);
        }
예제 #15
0
        public byte[] GetChunkData()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new NbtBinaryWriter(stream, true))
                {
                    writer.WriteVarInt((Blocks.Length * 2) + Skylight.Data.Length + Blocklight.Data.Length + BiomeId.Length);

                    for (var i = 0; i < Blocks.Length; i++)
                    {
                        writer.Write((ushort)((Blocks[i] << 4) | Metadata[i]));
                    }

                    writer.Write(Blocklight.Data);
                    writer.Write(Skylight.Data);

                    writer.Write(BiomeId);

                    writer.Flush();
                    writer.Close();
                }
                return(stream.ToArray());
            }
        }
예제 #16
0
        private byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            MemoryStream stream = new MemoryStream();
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                writer.Write(blocks);
                writer.Write(metadata.Data);
                writer.Write(skylight.Data);
                writer.Write(blocklight.Data);

                //RecalcHeight();
                writer.Write(height);

                for (int i = 0; i < biomeColor.Length; i++)
                {
                    writer.Write(biomeColor[i]);
                }

                foreach (var blockEntity in BlockEntities.Values)
                {
                    NbtFile file = new NbtFile(blockEntity);
                    file.BigEndian = false;
                    writer.Write(file.SaveToBuffer(NbtCompression.None));
                }

                writer.Flush();
                writer.Close();
            }

            var bytes = stream.ToArray();

            stream.Close();

            _cache = bytes;

            return(bytes);
        }
예제 #17
0
        public byte[] GetChunkData()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new NbtBinaryWriter(stream, true))
                {
                    writer.WriteVarInt((Blocks.Length*2) + Skylight.Data.Length + Blocklight.Data.Length + BiomeId.Length);

                    for (var i = 0; i < Blocks.Length; i++)
                        writer.Write((ushort) ((Blocks[i] << 4) | Metadata[i]));

                    writer.Write(Blocklight.Data);
                    writer.Write(Skylight.Data);

                    writer.Write(BiomeId);

                    writer.Flush();
                    writer.Close();
                }
                return stream.ToArray();
            }
        }
예제 #18
0
 internal override void WriteData(NbtBinaryWriter writeStream)
 {
     writeStream.Write(Value);
 }
예제 #19
0
        public byte[] GetMeta()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new NbtBinaryWriter(stream, true))
                {
                    writer.Write(IPAddress.HostToNetworkOrder(X));
                    writer.Write(IPAddress.HostToNetworkOrder(Z));
                    writer.Write((ushort) 0xffff); // bitmap

                    writer.Flush();
                    writer.Close();
                }
                return stream.ToArray();
            }
        }
예제 #20
0
파일: ChunkColumn.cs 프로젝트: oizma/MiNET
        public byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            using (MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream())
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                int topEmpty = 0;
                for (int ci = 15; ci > 0; ci--)
                {
                    if (chunks[ci].IsAllAir())
                    {
                        topEmpty = ci + 1;
                    }
                    else
                    {
                        break;
                    }
                }

                writer.Write((byte)topEmpty);
                Log.Debug($"Saved sending {16 - topEmpty} chunks");

                for (int ci = 0; ci < topEmpty; ci++)
                {
                    writer.Write((byte)0);
                    writer.Write(chunks[ci].GetBytes());
                }

                //RecalcHeight();
                writer.Write(height);

                //BiomeUtils utils = new BiomeUtils();
                //utils.PrecomputeBiomeColors();

                //InterpolateBiomes();

                writer.Write(biomeId);

                //for (int i = 0; i < biomeId.Length; i++)
                //{
                //	//var biome = biomeId[i];
                //	int color = biomeColor[i];
                //	writer.Write((int) (color & 0x00ffffff) /*| biome << 24*/);
                //}

                short extraSize = 0;
                writer.Write(extraSize);                 // No extra data

                if (BlockEntities.Count == 0)
                {
                    //NbtFile file = new NbtFile(new NbtCompound(string.Empty)) {BigEndian = false, UseVarInt = true};
                    //file.SaveToStream(writer.BaseStream, NbtCompression.None);
                }
                else
                {
                    foreach (NbtCompound blockEntity in BlockEntities.Values.ToArray())
                    {
                        NbtFile file = new NbtFile(blockEntity)
                        {
                            BigEndian = false, UseVarInt = true
                        };
                        file.SaveToStream(writer.BaseStream, NbtCompression.None);
                    }
                }

                _cache = stream.ToArray();
            }

            return(_cache);
        }
예제 #21
0
 internal override void WriteData(NbtBinaryWriter writeStream)
 {
     writeStream.Write(Value.Length);
     writeStream.Write(Value, 0, Value.Length);
 }
예제 #22
0
        public byte[] GetBytes()
        {
            if (_cache != null)
            {
                return(_cache);
            }

            using (MemoryStream stream = MiNetServer.MemoryStreamManager.GetStream())
            {
                NbtBinaryWriter writer = new NbtBinaryWriter(stream, true);

                int topEmpty = 16;
                for (int ci = 15; ci >= 0; ci--)
                {
                    if (chunks[ci].IsAllAir())
                    {
                        topEmpty = ci;
                    }
                    else
                    {
                        break;
                    }
                }

                writer.Write((byte)topEmpty);

                int sent = 0;
                for (int ci = 0; ci < topEmpty; ci++)
                {
                    writer.Write((byte)0);
                    writer.Write(chunks[ci].GetBytes());
                    sent++;
                }

                //Log.Debug($"Saved sending {16 - sent} chunks");

                //RecalcHeight();

                byte[] ba = new byte[512];
                Buffer.BlockCopy(height, 0, ba, 0, 512);
                writer.Write(ba);
                //Log.Debug($"Heights:\n{Package.HexDump(ba)}");

                //BiomeUtils utils = new BiomeUtils();
                //utils.PrecomputeBiomeColors();

                //InterpolateBiomes();

                writer.Write(biomeId);

                //for (int i = 0; i < biomeId.Length; i++)
                //{
                //	//var biome = biomeId[i];
                //	int color = biomeColor[i];
                //	writer.Write((int) (color & 0x00ffffff) /*| biome << 24*/);
                //}

                //short extraSize = 0;
                //writer.Write(extraSize); // No extra data

                // Count = SignedVarInt (zigzag)
                // Each entry
                // - Hash SignedVarint x << 12, z << 8, y
                // - Block data short

                writer.Write((byte)0);                 // Border blocks - nope

                VarInt.WriteSInt32(stream, 0);         // Block extradata count
                //VarInt.WriteSInt32(stream, 2);
                //VarInt.WriteSInt32(stream, 1 << 12 | 1 << 8 | 4);
                //writer.Write((byte)31);
                //writer.Write((byte)0);

                if (BlockEntities.Count == 0)
                {
                    //NbtFile file = new NbtFile(new NbtCompound(string.Empty)) {BigEndian = false, UseVarInt = true};
                    //file.SaveToStream(writer.BaseStream, NbtCompression.None);
                }
                else
                {
                    foreach (NbtCompound blockEntity in BlockEntities.Values.ToArray())
                    {
                        NbtFile file = new NbtFile(blockEntity)
                        {
                            BigEndian = false, UseVarInt = true
                        };
                        file.SaveToStream(writer.BaseStream, NbtCompression.None);
                    }
                }

                _cache = stream.ToArray();
            }

            return(_cache);
        }
예제 #23
0
 internal override void WriteData(NbtBinaryWriter writeStream) => writeStream.Write(this.Value);