Minecraft – How to gather entities into sets

minecraft-commandsminecraft-java-edition

Imagine that one day you decided to make an army of Mecha Combiner Robots in minecraft using commands. Each robot is made of 5 armor stands, CustomNamed mechahead, mechabody etc…A lot of em, yes

Then you spawn a few dozen of them in, just for testing purposes, and try to command one to raise their arm by teleporting an armor stand CustomNamed mecharightarm up a bit and… every single one of them raises their arm.

This is the kind of a problem that I ran into today, and a lot of times before when commands weren't as advanced as today, and just can't seem to be able to solve.

The logical solution is to break the entities up into separate sets, for instance by giving each armor stand an ID with scoreboard. But then, how does one select entities that have scores equal to another entity?

What are the solutions to running commands on sets of entities rather than just one?

Best Answer

I think that I understand your problem, and I think that this couod help you.

/execute as @e[tag=mechabody] at @s if score @s ID = #target ID as @e[tag=mecharightarm,sort=nearest,distance=..10] if score @s ID = #target ID run tp @s ~ ~ ~ ~ ~

With this command you are able to select a mecha via /scoreboard players set #target ID <targeted bot>.
Then you are able to execute the first command, only change the tp parameters, the coordinates are relative to the mecha's body.
Maybe you need to modify the distance selector a bit for your needings, but I think, that the arm would never be further than ten blocks feom the body.
You can use this command also for the other components of the robot. Just make sure that all parts of the robot get the same ID.
And, but I think this is clear, you need to add a scoreboard objective called ID first, with has to be a dummy scoreboard.
Hope that i hepled you.

Commander guy