I will use armour stands in this answer, because I am more familiar with them. It should be pretty easy to switch everything to AECs, if you want that.
There are multiple ways to kill everything except for one entity in a given space, the easiest one is to just tag an arbitrary one (limit=1
) and then kill all without that tag.
But in your case this constant summoning and killing is actually not required and causes way more lag than necessary. Instead you could check whether an entity already exists in that space before summoning a new armour stand or AEC there. So a VeinMiner/TreeCapitator-like system could for example work like this:
Summon an armour stand at the manually broken block (you seem to have already figured out that part):
/summon armor_stand <coordinates> {NoGravity:1,NoAI:1,Invisible:1,Marker:1,Tags:["vein"]}
I will use the tag "vein" for all armour stands that are used in this VeinMiner-like system.
Then repeatedly execute a function as/at all VeinMiner armour stands that have not summoned new armour stands around them yet:
/execute as @e[tag=vein,tag=!done] at @s run function vein:summon
The function looks like this:
execute positioned ~1 ~1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~ ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~ ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~ ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~-1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~-1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~1 ~-1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~ ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
# ~ ~ ~ check not necessary
execute positioned ~ ~ ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~-1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~-1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~ ~-1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~ ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~ ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~ ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~-1 ~1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~-1 ~ if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
execute positioned ~-1 ~-1 ~-1 if block ~ ~ ~ oak_log unless entity @e[tag=vein,distance=...1] run summon armor_stand ~ ~ ~ {Marker:1,NoGravity:1,NoAI:1,Invisible:1,Tags:["vein"]}
tag @s add done
Explanation: At each of the 26 blocks around the armour stand, a new armour stand is summoned only if there is an oak log there and not another VeinMiner armour stand already. Finally, the armour stand tags itself with "done" so that it doesn't need to check around it anymore in the following iterations.
This already automatically deals with loops and never summons any more armour stand than necessary.
You can stop the iteration when no more armour stands with the tag "vein
" and without the tag "done
" exist anymore (or after a certain number of repetitions, in case you apply it to e.g. stone in a default world).
Using a function is actually required in this case. If you first summoned armour stands around all without the "done" tag and then tagged everything with "done", you would also tag the new ones. If you first tagged all with "done" and then summoned new armour stands around all without the tag "done", then of course nothing would happen, because there would be none without the tag left.
Alternatively you would need yet another tag for armour stands that got created in the current round.
Note that a check for distance=0
does not always work correctly due to the bug MC-88533, so I'm using a radius of 0.1 here.
maker
tag makesunless entity @e[distance=0]
not work. Not sure if the same applys to effect clouds. Try changing the clouds to armor stands see if it stops summoning too many... (Please, make a backup before trying) – Bruno Rodrigues Feb 21 '20 at 3:48