Minecraft – How to fill in only certain blocks in minecraft 1.11.2

minecraft-commandsminecraft-java-edition

I need help. I am trying to make a map, and I tried to place all command blocks with NBT data in them, but its taking too long. Is there a way to only /fill in certain blocks? I tried this:

/fill 607.5 12 981.5 589.5 12 939.5 minecraft:command_block 0 replace command_block {Command:"/summon Item ~ ~-8 ~ {Item:{id:iron_nugget,Count:1}}"}

But this doesn't work. It says that its wrong. Can someone help me?

Best Answer

The /fill command implicitly splits syntax depending on whether the block you're filling in is a tile entity (blocks that hold extra data like chests, furnaces, or beacons). If you're not filling in a tile entity, you have the option to replace only certain blocks, e.g. /fill ~ ~ ~ ~3 ~3 ~3 stone 0 replace grass will only remove grass.

You're filling in command blocks, which are tile entities. Because of this (note that it's working as intended), you can only specify NBT after the replace argument, and don't have the option to replace only certain blocks.

So essentially, you can fill in a bunch of command blocks containing that command, but you can't only replace certain blocks while you do so. To do this, simply remove the second command_block from your command like so:

/fill 607.5 12 981.5 589.5 12 939.5 command_block 0 replace {Command:"/summon Item ~ ~-8 ~ {Item:{id:iron_nugget,Count:1}}"}