1

So I was trying to replace any stone or air in a 2x6x1 square in-front of me.

This is the command I am using.

/Fill 64 13 87 67 16 90 coal_ore 0 replace {stone air}

I am just getting into understanding some of the commands in Minecraft. This is the first one I am experimenting with. My background comes from using Excel. I am assuming an array is something I can use in a Minecraft command line.

Any help would be appreciated.

I tried looking into this but couldn't find my answer.

Glorfindel
  • 1,307
  • 2
  • 17
  • 28
user244406
  • 11
  • 1

2 Answers2

1

The wiki already lists every possible syntax of the /fill command, so you cannot use lists of blocks.

The closest you can get to that is using a block tag (archive). For example to replace all types of logs with stone, you can use this command:

/fill <coords> <coords> stone replace #logs

There are a few built-in block tags, but you can also create your own using a datapack.

Block tags only exist in Minecraft Java edition. At the time I'm writing this, the asker did not specify a Minecraft edition.

Fabian Röling
  • 20,534
  • 6
  • 38
  • 75
-1

Such functionality isn't in-built into the fill command. I've tried it before, and my solution was to have an armor stand scan over the area and replace the blocks you want.

Note this method is the most laggy, as you will have an armor stand at every block on the XZ plane at one point. It can be simplified, but it will take longer to run. Use at own risk, and do not use for exceedingly large areas!

You will need 3 dummy scoreboard objectives, named fillReplaceX, fillReplaceY and fillReplaceZ.

Start by resetting all the objectives:

/scoreboard players reset fillReplaceX
/scoreboard players reset fillReplaceY
/scoreboard players reset fillReplaceZ

Then summon a unique armor stand:

/execute positioned [corner of area, lowest coordinates xyz] run summon minecraft:armor_stand ~ ~ ~ {Tags=["fillReplaceAlongX"]}

Then power this:

[repeat] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongX] at @s if score @s fillReplaceX matches ..[x size of area] run summon minecraft:armor_stand ~ ~ ~ {Tags=["fillReplaceAlongZ"]}
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongX] at @s run tp @s ~1 ~ ~
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongX] run scoreboard players add @s fillReplaceX 1

Then:

/execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongX] run scoreboard players reset @s fillReplaceX
/kill @e[type=minecraft:armor_stand,tag=fillReplaceAlongX]

Once that is completed power this:

[repeat] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongZ] at @s if score @s fillReplaceZ matches ..[z size of area] run summon minecraft:armor_stand ~ ~ ~ {Tags=["fillReplaceFinal"]}
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongZ] at @s run tp @s ~ ~ ~1
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongZ] run scoreboard players add @s fillReplaceZ 1

Then:

/execute as @e[type=minecraft:armor_stand,tag=fillReplaceAlongZ] run scoreboard players reset @s fillReplaceZ
/kill @e[type=minecraft:armor_stand,tag=fillReplaceAlongZ]

Once that is completed power this:

[repeat] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceFinal] at @s if score @s fillReplaceY matches ..[y size of area] run [COMMAND TO RUN OVER AREA]
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceFinal] at @s run tp @s ~ ~1 ~
[conditional] /execute as @e[type=minecraft:armor_stand,tag=fillReplaceFinal] run scoreboard players add @s fillReplaceY 1

And finally, kill the armor stands.

/execute as @e[type=minecraft:armor_stand,tag=fillReplaceFinal] run scoreboard players reset @s fillReplaceY
/kill @e[type=minecraft:armor_stand,tag=fillReplaceFinal]

Replace [COMMAND TO RUN OVER AREA] with what will be done for every block in the area. If you wanted to replace all stone in the area with air, then enter:

execute if block ~ ~ ~ minecraft:stone run setblock ~ ~ ~ minecraft:air

I may have gotten some syntax wrong, as this is from memory. LMK and I will fix.

Edit: If you want to run multiple commands over the area, just add another command block as a conditional chain, before the TP command:

/execute as @e[type=minecraft:armor_stand,tag=fillReplaceFinal] at @s run [COMMAND TO RUN OVER AREA]
AMJ
  • 954
  • 6
  • 17
  • That's an interest trick that I have used before, but it is not required in this case, because /fill exists. It's also not at all what the question was about. – Fabian Röling Feb 22 '20 at 14:50
  • OP wanted a way to replace certain blocks in an area with other certain blocks. This method does that. If he wanted to replace stone and air with coal_ore, he can do that with execute if block ~ ~ ~ stone run setblock ~ ~ ~ coal_ore and execute if block ~ ~ ~ air run setblock ~ ~ ~ coal_ore in my method. – AMJ Feb 22 '20 at 22:29
  • 1
    But they can simply do /fill <coords> coal_ore replace stone and /fill <coords> coal_ore replace air as well! That's WAY simpler and causes WAY less lag. – Fabian Röling Feb 22 '20 at 23:50
  • Oh, sorry, I was under the impression that 'replace' was a method of placing the blocks, like 'destroy' would break the block that was already there and drop its item. I didn't know you could actually use it to replace certain blocks! My mistake. – AMJ Feb 23 '20 at 11:42