I am aware that ordinarily in Minecraft one can use:

\setblock x y z minecraft:block0 0 replace minecraft:blockname1

to set a block with the ID name: block0 on the coordinate, but only if the block which was before has ID name: block1; this does however not seem to be the case if the block I desire to set is chest (or other blocks which can contain things, such as for instance hoppers). If I type

\setblock x y z minecraft:chest

it works fine

\setblock x y z minecraft:chest 0 replace

works as well; however

\setblock x y z minecraft:chest 0 replace minecraft:block1

(of course I don't write block1, I instead use any real blockname)

fails with the error message:

Data tag parsing failed: Invalid tag encountered, expected '{' as first char.

I have (obviously) attempted this:

\setblock x y z minecraft:chest 0 {} replace minecraft:block1

Which does cause chest to be placed, but it does however not only do if the block that was there before had ID name: block1.

My question: Is there a way to use the setblock command to set a chest (or other item containing blocks) but only if it replaces a specific other block?

  • Dumb clarification question incoming: you are replacing block1 with an actual block id in your implementation, right? – Unionhawk Mar 17 '17 at 16:49
  • 1
    yes, (as i have just edited into the question) block1 and block0 are only placeholders for the actual ID names – Nikolaj Mar 17 '17 at 16:55

/setblock does not support replacing specific blocks. The /fill command does:

/fill x1 y1 z1 x2 y2 z2 block1 0 replace block2 0

However, if "block1" is a tile entity, then you cannot replace a specific block and must instead supply NBT data. See this explanation by Searge:

Replacing blocks with tile entities is not supported, this is due to a limitation in the parsing of commands. It may be changed in the future, but not until after 1.8.

A chest is a tile entity, meaning you cannot use this to replace a specific block with a chest.

As a work-around, you could detect the existence of the particular block first using /testforblock:

/testforblock x y z minecraft:stone 0

And then use /setblock if that command succeeded:

/setblock x y z minecraft:chest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.