I want to make a system that tests for a specific player at specific coordinates with a specific item?

I want to make a system that tests for a specific player at specific coordinates with a specific item? And also how do I get one redstone output out of all the commands at once?
I tried to do /testfor [x=X,y=Y,z=Z,r=R]
And /testfor {Inventory:[{id:"minecraft:slime_ball"}]}
Both work, but I can't test for 1 specific player, I can only check for all the players, I need help please.


Solution 1:

you can check all of that in one command like this:

/testfor @p[name=PlayerName,x=X,y=Y,z=Z,r=R] {Inventory:[{id:minecraft:slime_ball}]}

Solution 2:

In 1.13+, you need to use /execute if entity in lieu of /testfor. There are also some additional changes you need to be aware of:

  • You need to move the NBT data inside the target selector, using the nbt argument.
  • You need to replace the r argument with the distance argument, and it's done a little differently.
  • You can also implement a single command to run when the test passes.

So here is the 1.13+ way to do it:

/execute if entity @p[x=X,y=Y,z=Z,distance=0..5,nbt={Inventory:[{id:"minecraft:slime_ball"}]}] run ...

This command will only run if a player has a slime ball within five blocks of coordinates (X, Y, Z).