Quiero ejecutar un comando para un puesto de armadura si el cerdo más cercano tiene una etiqueta específica.
Los comandos que he probado hasta ahora ...
execute as @e[type=armor_stand] at @s if entity @e[type=pig,limit=1,sort=nearest,tag=carrot] run <command>
no funciona porque verifica si existe "zanahoria" -pig.
Tener un cerdo sin etiqueta "zanahoria" entre el soporte de la armadura y el cerdo "zanahoria" solo resultará en la prueba aprobada .
execute as @e[type=armor_stand] at @s as @e[type=pig,limit=1,sort=nearest] if entity @s[tag=carrot] run <command>
podría haber funcionado pero cambió el selector.
Ejecutar como selector si la entidad más cercana tiene una etiqueta
minecraft-java-edition
minecraft-commands
Respuesta
Use el parámetro as
para cambiar el ejecutor al soporte de armadura al final.
execute
as @e[type=armor_stand,limit=1] # ARMOUR STAND NOW HAS CONTROL
at @s # Move the location to me.
as @e[type=pig,limit=1,sort=nearest] # NEAREST PIG NOW HAS CONTROL
if entity @s[tag=carrot] # If I have the tag carrot, continue to the next step, otherwise stop.
as @e[type=armor_stand,limit=1] # ARMOUR STAND NOW HAS CONTROL
say The nearest pig to me has the carrot tag!