4

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?

2
  • Java Edition or Bedrock? – ExpertCoder14 Mar 1 at 15:55
  • Oops! Java edition, I'll add it now. – Wicked Grinn Mar 1 at 18:03
2

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
8
  • I tried it out and ran into a few issues. But mainly that using "data get entity" and such only works when targetting a single entity, so I had to edit commands which may have lead to the whole thing not working. But, this has given me a lot of new ideas as I had never thought of using something like that last command. (Getting data from one thing and modifying something else with it) – Wicked Grinn Mar 2 at 16:28
  • I tried using this new idea to check directly for the nbt of the block beneath the player, but block type is not an nbt so nothing gets returned if the block has no special nbt. – Wicked Grinn Mar 2 at 16:29
  • I'm gonna try using "execute as @a[scores={camouflaged=1..}] at @s run data get block ~ ~-1 ~ id". It worked with a chest at the very least... Well, not exactly that, but you get the idea* – Wicked Grinn Mar 2 at 16:38
  • Well nope, it actually ONLY works with chests and the like. – Wicked Grinn Mar 2 at 16:40
  • You can do that with block entities only, but you need the arrow trick for all other blocks. I updated my answer, you need to wait one tick between summoning the arrow and getting its data. – ExpertCoder14 Mar 2 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.