Minecraft – How to add X Y Z coordinates to /testfor commands

minecraft-commandsminecraft-java-edition

I am trying to make a money wars mini-game, and to upgrade the generators, you throw a certain ingot on the generator block, and then it upgrades it. I know you can put:

/testfor @e[type=Item] {Item:{id:whatever id}}

But where would I put the X Y Z coordinates?

Best Answer

This syntax should work:

/testfor @e[x=a,y=b,z=c,r=1,type=Item]

Where a is the x co-ordinate, b is the y co-ordinate, and c is the z co-ordinate. Note that the r=1 radius attribute is necessary to detect all items in the 1-block area, instead of only detecting items at that exact co-ordinate.

Example:

/testfor @e[x=25,y=64,z=79,r=1,type=Item]