예제 #1
0
        public void ToStream(IMinecraftStream stream)
        {
            stream.WriteVarInt(Count);

            foreach (var entry in _entries)
            {
                stream.WriteInt(entry.Coordinates.X);
                stream.WriteInt(entry.Coordinates.Z);
                stream.WriteUShort(entry.PrimaryBitMap);
            }
        }
예제 #2
0
        // TODO: Convert to RawData
        public void ToStream(IMinecraftStream stream)
        {
            var OverWorld = true; // TODO: From World class

            stream.WriteVarInt(Coordinates.X);
            stream.WriteVarInt(Coordinates.Z);
            stream.WriteBoolean(OverWorld);
            stream.WriteUShort(PrimaryBitMap);

            var sectionCount = GetSectionCount(PrimaryBitMap);

            var chunkRawBlocks      = new byte[sectionCount * TwoByteData];
            var chunkRawBlocksLight = new byte[sectionCount * HalfByteData];
            var chunkRawSkylight    = new byte[sectionCount * HalfByteData];

            var size = sectionCount * (TwoByteData + HalfByteData + (OverWorld ? HalfByteData : 0)) + (OverWorld ? Biomes.Length : 0);
            var data = new byte[size];

            for (int y = 0, i = 0; y < Sections.Length; y++)
            {
                var section = Sections[y];

                if (Sections[i].IsFilled)
                {
                    // Blocks & Metadata
                    //Array.Copy(section.RawBlocks, 0, chunkRawBlocks, i * section.RawBlocks.Length, section.RawBlocks.Length);
                    // Light
                    //Array.Copy(section.RawBlockLight, 0, chunkRawBlocksLight, i * section.RawBlockLight.Length, section.RawBlockLight.Length);
                    // Sky light
                    //if (OverWorld)
                    //    Array.Copy(section.RawSkyLight, 0, chunkRawSkylight, i  *section.RawSkyLight.Length, section.RawSkyLight.Length);

                    i++;
                }
            }

            Array.Copy(chunkRawBlocks, 0, data, 0, chunkRawBlocks.Length);
            Array.Copy(chunkRawBlocksLight, 0, data, chunkRawBlocks.Length, chunkRawBlocksLight.Length);
            Array.Copy(chunkRawSkylight, 0, data, chunkRawBlocks.Length + chunkRawBlocksLight.Length, chunkRawSkylight.Length);
            if (OverWorld)
            {
                Array.Copy(Biomes, 0, data, data.Length - Biomes.Length, Biomes.Length);
            }

            stream.WriteVarInt(size);
            stream.WriteByteArray(data);
        }