Minecraft – how to test relative square area

minecraft-commandsminecraft-java-edition

I'm making a minesweeper minigame, and I'm using NoAI chickens to represent mines, and armorstands to represent everything else. I want to increase the armorstands' scoreboard value by one for each adjacent chicken (diagonally or cardinally). I've figured out that it would be easiest to use an execute command from the chickens, but the problem is that @e[type=ArmorStand,r=1] doesn't get the diagonals, and @e[type=ArmorStand,r=2] gets armorstands two spaces away. Any ideas?

Best Answer

I found a solution myself. It involves using the relative coordinates in the /execute command. The command is:

/execute @e[type=Chicken] ~-1 ~ ~-1 scoreboard players add @e[type=ArmorStand,dx=2,dz=2] mine 1