Exemple #1
0
        public static Chunk FromReader(IMinecraftDataReader reader)
        {
            var overWorld     = true;// TODO: From World class
            var coordinates   = new Coordinates2D(reader.ReadInt(), reader.ReadInt());
            var groundUp      = reader.ReadBoolean();
            var primaryBitMap = reader.ReadUShort();

            var value = new Chunk(coordinates);

            value.OverWorld     = overWorld;
            value.GroundUp      = groundUp;
            value.PrimaryBitMap = primaryBitMap;

            var size = reader.ReadVarInt();
            var data = reader.ReadByteArray(size);

            var sectionCount = GetSectionCount(value.PrimaryBitMap);

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

            Array.Copy(data, 0, chunkRawBlocks, 0, chunkRawBlocks.Length);
            Array.Copy(data, chunkRawBlocks.Length, chunkRawBlocksLight, 0, chunkRawBlocksLight.Length);
            Array.Copy(data, chunkRawBlocks.Length + chunkRawBlocksLight.Length, chunkRawSkylight, 0, chunkRawSkylight.Length);

            for (int y = 0, i = 0; y < 16; y++)
            {
                if ((value.PrimaryBitMap & (1 << y)) > 0)
                {
                    // Blocks & Metadata
                    var rawBlocks = new byte[TwoByteData];
                    Array.Copy(chunkRawBlocks, i * rawBlocks.Length, rawBlocks, 0, rawBlocks.Length);

                    // Light, convert to 1 byte per block
                    var rawBlockLight = new byte[HalfByteData];
                    Array.Copy(chunkRawSkylight, i * rawBlockLight.Length, rawBlockLight, 0, rawBlockLight.Length);

                    // Sky light, convert to 1 byte per block
                    var rawSkyLight = new byte[HalfByteData];
                    if (value.OverWorld)
                    {
                        Array.Copy(chunkRawSkylight, i * rawSkyLight.Length, rawSkyLight, 0, rawSkyLight.Length);
                    }

                    value.Sections[i].BuildFromRawData(rawBlocks, rawBlockLight, rawSkyLight);
                    i++;
                }
            }
            if (value.GroundUp)
            {
                Array.Copy(data, data.Length - value.Biomes.Length, value.Biomes, 0, value.Biomes.Length);
            }

            return(value);
        }
Exemple #2
0
        public static ChunkColumnMetadataList FromReader(IMinecraftDataReader reader)
        {
            var value = new ChunkColumnMetadataList();

            var count = reader.ReadVarInt();

            for (int i = 0; i < count; i++)
            {
                value[i] = new ChunkColumnMetadata
                {
                    Coordinates   = new Coordinates2D(reader.ReadInt(), reader.ReadInt()),
                    PrimaryBitMap = reader.ReadUShort()
                }
            }
            ;

            return(value);
        }