Minecraft executing on an entity not working

minecraft-commandsminecraft-java-edition

What i am trying to do is make an entity say hi when it is in a certain radius of another entity. I have used a scoreboard called PigProgress. What is happening is that I am giving a score of 1 to every porkchop item dropped. Then when a diamond is dropped next to i want them both to dissappear an then other things to happen.

I have tried this command but it has failed

/execute @e[score_PigProgress_min=1,score=1] ~ ~ ~ /execute @e[type=Item,r=1] {Item:{id:minecraft:diamond}} ~ ~ ~ /say hi

Best Answer

There are two things wrong with your command.

  1. The target selector for the first execute is wrong, although I assume this to be a typo. It should (probably) be
    @e[score_PigProgress_min=1,score_PigProgress=1]
    although the second part is not really necessary, unless porkchops with a score of 2 are a different thing.

  2. /execute does not support matching dataTags, which is what you are attempting in the second execute. You will have to assign a scoreboard value for diamond items, similar to what you did with the porkchops.

Lastly, to achieve what you want, I suggest summoning an invisible Armor Stand to work using the double execute and work from there. I.e.

/execute @e[type=Item,score_PigProgress_min=1] ~ ~ ~ /execute @e[type=Item,score_isDiamond_min=1,r=1] ~ ~ ~ /summon ArmorStand ~ ~ ~ {CustomName:"Marker1",Marker:1b,Invisible:1,Invulnerable:1,NoGravity:1}

This assumes all pork chops and only those have a PigProgress score of 1 or more, and all Diamond Items (and only those) have a isDiamond score of 1 or more.

Now you can execute everything else (/killing the items, saying "Hi", etc.) from the armor stand using

/execute @e[type=ArmorStand,name=Marker1] ~ ~ ~ <command>

Don't forget to kill the armor stand in the end as well.