Ejemplo n.º 1
0
        public void Parse(ref byte[] data)
        {
            McShort.TryParse(ref data, out short NonAirBlocksCount);             // short
            McUnsignedByte.TryParse(ref data, out byte bitsPerBlock);            // byte

            IPalette palette = Palette.ChoosePalette(bitsPerBlock);

            palette.Read(ref data);
            uint individualValueMask = (uint)((1 << bitsPerBlock) - 1);

            McVarint.TryParse(ref data, out int dataArrayLength);
            McULongArray.TryParse(ref data, dataArrayLength, out ulong[] dataArray);


            //Parallel.For(0, SizeY, (y) =>
            for (int y = 0; y < SizeY; y++)
            {
                for (int z = 0; z < SizeZ; z++)
                {
                    for (int x = 0; x < SizeX; x++)
                    {
                        int blockNumber = (((y * SizeY) + z) * SizeZ) + x;
                        int startLong   = blockNumber / (64 / bitsPerBlock);
                        int startOffset = (blockNumber - startLong * (64 / bitsPerBlock)) * bitsPerBlock;

                        uint intData;
                        intData = (uint)(dataArray[startLong] >> startOffset);

                        intData &= individualValueMask;

                        BlockId state = new BlockId(palette.StateForId(intData).Id);
                        SetState(x, y, z, state);
                    }
                }
            }
            //});
        }
Ejemplo n.º 2
0
 public void SetState(int x, int y, int z, BlockId state)
 {
     blockIds[x, y, z] = state;
 }