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[] 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); }
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()); } }
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); }
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()); } }
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()); } }
public 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); 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); } int extraSize = 0; writer.Write(extraSize); // No extra data if (BlockEntities.Count == 0) { NbtFile file = new NbtFile(new NbtCompound(string.Empty)) { BigEndian = false }; file.SaveToStream(writer.BaseStream, NbtCompression.None); } else { foreach (NbtCompound blockEntity in BlockEntities.Values.ToArray()) { NbtFile file = new NbtFile(blockEntity) { BigEndian = false }; file.SaveToStream(writer.BaseStream, NbtCompression.None); } } writer.Flush(); writer.Close(); } var bytes = stream.ToArray(); stream.Close(); _cache = bytes; return(bytes); }
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[] 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(); } }