Minecraft – How to make the /fill command add blocks, but only on top of certain blocks

minecraft-commandsminecraft-java-edition

I'm looking for more information about the /fill command. I want to replace air blocks with another block, but only if they have a stone block below them. The command /fill ~ ~ ~ ~25 ~-5 ~25 air 0 replace dirt will replace every single air block with dirt, and that is obviously not the result that I want.

How can I add a layer of dirt on top of stone blocks, without filling the world with dirt?

Best Answer

There is no way to make it with one command, but you can achieve it with 5.

/clone ~ ~ ~ ~25 ~5 ~25 ~ 200 ~ filtered force minecraft:stone
/fill ~ 200 ~ ~5 225 ~5 minecraft:grass 0 replace minecraft:stone
/clone ~ ~ ~ ~25 ~5 ~25 ~ 199 ~ filtered force minecraft:stone
/clone ~ 200 ~ ~25 225 ~25 ~ ~1 ~ filtered force minecraft:grass
/fill ~ 200 ~ ~25 225 ~25 air

It will create a copy of stone in sky, check for having air to place a block, an then return blocks and clear the sky.