Minecraft detecting if a player in a certain place has a certain item

minecraft-commandsminecraft-java-edition

I'm building a city themed parkour map and I'm trying to figure out how to detect if a player is in a certain place and has a certain item in his inventory. I've tried using a combination of these two commands:

/execute if entity @p[x=-628,y=120,z=-157,dx=0,dy=0,dz=3]

and

/execute if entity @a[nbt={Inventory:[{id:"minecraft:rabbit_stew"}]}]

but I just can't figure it out. I'd appreciate your help.

Best Answer

Try combining those into one command:

execute if entity @a[x=-628,y=120,z=-157,dx=0,dy=0,dz=3,nbt={Inventory:[{id:"minecraft:rabbit_stew"}]}]