Using /setblock, how do I set a command block with a prefilled command?
By David Jones •
Using /setblock, I'd like to set a command block with a command already pre-filled inside of it.
My current code looks like this, but it doesn't seem to work:
setblock <x> <y> <z> command_block {TileEntityData:{Command:"testfor @p[_=1]"}}What's wrong with it, and what do I need to change?
1 Answer
You will need to do two things:
- Firstly, there are two other parts to the
/setblockcommand that need to be present; the datavalue, and the method of handling the existing block, if any. - Secondly, the data tag at the end should just be
{Command: "testfor @p[_=1]"}, without the TileEntityData bit.
Thus, the resulting command should be along the lines of
/setblock <x> <y> <z> command_block 0 replace {Command:"testfor @p[_=1]"}As proof, here's a shot of me using that command:
And here's the result: