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:
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
C: indicates a conditional command block.