public void WriteTo(MinecraftStream stream) { if (Cache != null) { stream.Write(Cache); return; } byte[] sectionData; int sectionBitmask = 0; using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { for (int i = 0; i < Sections.Length; i++) { ChunkSection section = Sections[i]; if (section.IsAllAir) { continue; } sectionBitmask |= 1 << i; section.WriteTo(mc, true); } } sectionData = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { using (MinecraftStream mc = new MinecraftStream(ms)) { mc.WriteInt(Coordinates.X); mc.WriteInt(Coordinates.Z); mc.WriteBool(true); mc.WriteVarInt(sectionBitmask); //Primary Bitmask mc.WriteVarInt(sectionData.Length + 256); mc.Write(sectionData, 0, sectionData.Length); mc.Write(Biomes); mc.WriteVarInt(0); //No block entities for now } Cache = ms.ToArray(); } stream.Write(Cache); }
public ChunkColumn(ChunkCoordinates coordinates) { Coordinates = coordinates; Sections = new ChunkSection[16]; Biomes = new byte[Depth * Width]; for (int i = 0; i < Sections.Length; i++) { Sections[i] = new ChunkSection(); } for (int i = 0; i < Biomes.Length; i++) { Biomes[i] = 1; //Plains } for (int i = 0; i < HeightMap.Length; i++) { HeightMap[i] = 0; } }