public void SetBlock(int x, int y, int z, IBlockState blockState) { var id = blockState != null?BlockPalette.GetId(blockState) : Nil; if (id == -1) // block not registered { Resize((byte)(BlockPalette.BitsPerBlock + 1)); id = BlockPalette.GetId(blockState); if (id == -1) { throw new InvalidOperationException("Invalid block state palette id"); } } var index = Index(x, y, z); _nBitsArray[index] = id; _blockCount = ushort.MaxValue; }
/// <summary> /// Resize the storage to match the bitsPerBlock /// </summary> /// <param name="bitsPerBlock">The number of bits used to store a block state</param> private void Resize(byte bitsPerBlock) { var previousDataBits = _nBitsArray; var previousBlockPalette = BlockPalette; if (!UpdatePalette(bitsPerBlock)) { return; } for (var i = 0; i < previousDataBits.Capacity; i++) { var blockStateId = previousDataBits[i]; if (blockStateId == 0) { continue; } var blockState = previousBlockPalette.GetBlockState(blockStateId); _nBitsArray[i] = BlockPalette.GetId(blockState); } }