How to transform the ID of a block at a certain position into an NBT string?

I'm trying to make a camouflage skill and I want to summon two falling block entities on the player to make it look like they're just two blocks standing there instead of a player. I know how to summon falling blocks that look like a specific block, but I want to know if it's possible to summon a block equal to the block the player is standing on.

I know that the tile ID of falling blocks is stored in NBT, so this boils down to the fundamental issue:

How do you get an NBT string containing the namespaced ID of a block at a certain position, and write it to the falling blocks' NBT data?


This question boils down to the fundamental issue of transforming the block ID at a certain position to an NBT string. There is a clever workaround to do this:

  1. Clone the block to test to another location.
  2. Summon an arrow with downward motion above the block which will shoot downwards and impact the cloned block.
  3. Wait one tick for the arrow to land on the block.
  4. Take the arrow's inBlockState.Name NBT tag which is the block the arrow is in.

Prerequisites:

  • Mark the chunk at (−30000000, 1600) to be force loaded with the /forceload command.

Commands:

clone <x> <y> <z> <x> <y> <z> -30000000 0 1604
summon arrow -30000000 1 1604 {Tags:["blockTest"]}
schedule function ...

The function targeted by /schedule should contain the following command:

data get entity @e[type=minecraft:arrow,tag=blockTest] inBlockState.Name
kill @e[type=minecraft:arrow,tag=blockTest]

In your case, you want to copy this data to a falling block's tile name, so instead of the /data get command above, use this one instead:

data modify entity @e[type=minecraft:falling_block,tag=camouflage] BlockState.Name set from entity @e[type=minecraft:arrow,tag=blockTest] inBlockState.Name