How to setblock snow_layer only if block below is a full-block?
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
- 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. - 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
- Replace
<x> <y> <z>
,<x> <y+1> <z>
with allocated blocks' coordinates from above
After trying many things, I finally came up with a solution that works all the time (I hope) and doesn't change any block:
Instead of creating the snow layer with:
/setblock ~ ~ ~ snow_layer
I use the command:
/summon FallingSand ~ ~ ~ {Block:"minecraft:snow_layer",Time:1,DropItem:false}
wich does the job quite well, and because of DropItem:false
it doesn't even drop the snow if placing it fails. :)
NOTE:
Summoning falling sand at the same block where there's an existing one will cause it to be deleted, so only summon the sand if there's air! In my example:
Summon FallingSand that become a snow_layer AT every player:
/execute @a ~ ~ ~
detect ~ ~ ~ air 0 /summon FallingSand ~ ~ ~ {...}