Minecraft – How to setblock snow_layer only if block below is a full-block

minecraft-commandsminecraft-java-edition

Or is there actually any way to do that?

Basically I do a /setblock ~ ~ ~ snow_layer at the player but if it's above something that snow layer can't be on (eg. slab,sign,grass) it just looks buggy. :/
I could avoid it with causing a block update right after creating it.

Any idea is helpful even if you're not sure if it works or not! (best would be a one command block method)

As you can see on the picture looking for {OnGround:true} doesn't solve it all the time:
enter image description here

UPDATE:
I could do a /setblock above it, but that may remove other block, so I'm looking for a safer idea.

UPDATE 2:
Changed title to represent the problem more clearly.

Best Answer

Simple method

Run the following 2 commands sequentially in 1 tick:

/execute @p ~ ~ ~ setblock ~ ~ ~ snow_layer 0 keep
/execute @p ~ ~ ~ detect ~ ~ ~ snow_layer 0 clone ~ ~1 ~ ~ ~1 ~ ~ ~1 ~ replace force

First command places snow layer at player's position, and second command will update the snow layer and remove improper ones. Using this method will constantly update adjacent blocks around the block that the player's head is in, if you don't want that use advanced method instead.


Advanced method

  1. First you need to allocate 2 blocks(at <x> <y> <z> and <x> <y+1> <z>) on your world to this command block system. Which should be independant and kept away from any other blocks or entities.
  2. Following commands will run sequentially in 1 tick when done (works best with 20Hz fill/clone clock):

    /execute @p ~ ~.999999999999999 ~ clone ~ ~-1 ~ ~ ~ ~ <x> <y> <z> replace
    /setblock <x> <y+1> <z> snow_layer 0 keep
    /clone <x> <y> <z> <x> <y> <z> <x> <y> <z> replace force
    /execute @p ~ ~.999999999999999 ~ detect <x> <y+1> <z> snow_layer 0 setblock ~ ~ ~ snow_layer

  3. Replace <x> <y> <z>, <x> <y+1> <z> with allocated blocks' coordinates from above