Use
/blockdata x y z {Items:[0:{id:minecraft:wooden_button,tag:{CanPlaceOn:["minecraft:stonebrick"]},Count:1}]}
Which can add to an already filled chest. Replace x y z
with the coordinates.
The /blockdata
command changes, well, the data of a block (go figure!) Basically, I change the data of a chest to include a wooden button with the tag CanPlaceOn
. Pretty simple, really.
You cannot use the "~" character in selectors, meaning you'd need to rely on command syntax and not selector syntax. You cannot use relative coordinates with /testfor
as its command syntax does not support it.
You would instead need to place an entity at the desired position and execute from it relatively using /execute
:
/execute <target> X Y Z <command>
"target" is the target entity to change the coordinate origin to, while XYZ is going to further modify the origin. Using relative coordinates would cause "command" to be executed relative from the target's position.
Sample armor stand to create:
/summon ArmorStand X Y Z {Tags:["anchor"]}
For example, assuming there is an armor stand tagged with "anchor" at the intended location, the following tests for players relative to the armor stand:
/execute @e[type=ArmorStand,tag=anchor] ~1 ~4 ~-3 /testfor @a[dx=0,dz=0,dy=102]
/execute @e[type=ArmorStand,tag=anchor] ~1 ~4 ~3 /testfor @a[dx=0,dz=0,dy=102]
Best Answer
Try setting the command block to chain and conditional and chaining it after a repeating command block that checks if a lever is flicked, the command should look something like this:
/execute if block <coordinates to the lever> minecraft:lever[powered=true]