TransWikia.com

How to check if entities have the same position

Arqade Asked by aaaaaaaaaaaaaaa on July 30, 2021

Im making a Snake Game using Armor Stands on the positions of table game and for the body of the snake. I want to check when the the Armor Stand {Tags:["head"]} of the snake has the same position of an Armor Stand {Tags:["food"]} of a food.
(1.16 Version)

enter image description here

(The others Armor Stands are invisible)

2 Answers

I already know two ways to do that.

1. Testfor:

The testfor of 1.12 can be rewrited as, for 1.16:

execute at @e[tag=food] if @e[tag=head,distance=..0.5] run tellraw @a "Same Position Check"

2. Execute Store:

execute store result score @e[tag=head] X run data get entity @e[tag=head] Pos[0]; for X coordinate

execute store result score @e[tag=head] Y run data get entity @e[tag=head] Pos[1]; for Y coordinate

execute store result score @e[tag=head] Z run data get entity @e[tag=head] Pos[2]; for Z coordinate

execute store result score @e[tag=food] X run data get entity @e[tag=food] Pos[0]; for X coordinate

execute store result score @e[tag=food] Y run data get entity @e[tag=food] Pos[1]; for Y coordinate

execute store result score @e[tag=food] Z run data get entity @e[tag=food] Pos[2]; for Z coordinate

And then, test the scoreboards scores of the coordinates X,Y and Z:

execute if score @e[tag=head] X = @e[tag=food] X if score @e[tag=head] Y = @e[tag=food] Y if score @e[tag=head] Z = @e[tag=food] Z run tellraw @a "Same Position Check"

Correct answer by aaaaaaaaaaaaaaa on July 30, 2021

How

Check if the other armor stand is within distance 0.5.

Selector

@e[name=“Example”,distance=..0.5]

Testfor

1.13+

/execute if @e[name=“Example”,distance=..0.5]

1.12-

/testfor @e[name=“Example”,distance=..0.5]

Answered by Penguin on July 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP