internal override void WriteData(NbtBinaryWriter writeStream) { writeStream.Write(Value.Length); for (int i = 0; i < Value.Length; i++) { writeStream.Write(Value[i]); } }
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); }
internal override void WriteTag(NbtBinaryWriter writeStream) { writeStream.Write(NbtTagType.IntArray); if (Name == null) { throw new NbtFormatException("Name is null"); } writeStream.Write(Name); WriteData(writeStream); }
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); }
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); } }
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); }
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); }
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()); }
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()); } }
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()); } }
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); }
internal override void WriteData(NbtBinaryWriter writeStream) { foreach (NbtTag tag in tags.Values) { tag.WriteTag(writeStream); } writeStream.Write(NbtTagType.End); }
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); }
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); }
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()); } }
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); }
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(); } }
internal override void WriteData(NbtBinaryWriter writeStream) { writeStream.Write(Value); }
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(); } }
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); }
internal override void WriteData(NbtBinaryWriter writeStream) { writeStream.Write(Value.Length); writeStream.Write(Value, 0, Value.Length); }
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); }
internal override void WriteData(NbtBinaryWriter writeStream) => writeStream.Write(this.Value);