Replacing blocks with /setblock won't work
I am using version 1.8.9.
So I used this command:
/setblock ~ ~6 ~ air 0 replace end_portal
And it worked perfectly fine, but when I swapped the two blocks with this command,
/setblock ~ ~6 ~ end_portal 0 replace air
It didn't work, and displayed the error:
Data tag parsing failed invalid tag encountered expected '{' as first char.
Does anyone know what is causing this?
setblock
cannot replace
specific blocks like that; only fill
can. Putting replace
in a setblock
command just tells the command not to drop any items from the replaced block. Your first command appears to be working, but it's actually ignoring the end_portal
bit completely. It'd set any block to air: dirt, stone, anything.
The correct syntax for the setblock
command is/setblock <x> <y> <z> <block> [dataValue|state] [oldBlockHandling] [dataTag]
So your original command,/setblock ~ ~6 ~ air 0 replace end_portal
should reasonably fail for two reasons:
- The
air
block does not support NBT -
end_portal
not valid NBT data
What actually happens is that Minecraft says, "Well, air
doesn't support NBT, so I'll just ignore this bit that should be NBT." Your command, therefore, is equivalent to/setblock ~ ~6 ~ air 0 replace
But with your second command, Minecraft says "The end_portal
block does support NBT, so let's parse this--hey! This isn't valid NBT!" and throws an error.
If you're using command blocks, you can test for the air block explicitly, and then only set the end portal if the test succeeded:
/testforblock <x> <y> <z> air
C: /setblock <x> <y> <z> end_portal
Where C:
indicates a conditional command block.
Or just use /fill ~ ~-6 ~ ~ ~-6 ~ fill only that one block