2

So when I break an oak_log block I summon an area_effect_cloud with the tag of B.Spawn at the block I jus broke.

now I use this command to summon a 3x3x3 area_effect_cloud cube around the [tag=B.Spawn] entity

execute at @e[tag=B.Spawn] positioned ~-1 ~-1 ~-1 unless entity @e[tag=B.Cell,distance=...5] run summon area_effect_cloud ~ ~ ~ {Tags:['B.Cell'],Duration:2147483647}

Now every [tag=B.Spawn] gets killed and every [tag=B.Cell] gets the tag of B.Spawn and summons again a 3x3x3 cube around it.

This brings a lot of entities who overlap eachother causing 20000 entities in just a 5x5x5 cube.

I need a command who kills all entities within its block so there is only one left per block.

I tried:

execute at @e[tag=B.Cell] if entity @e[tag=B.Cell,distance=...99] run kill @e[tag=B.Cell,distance=...99]

but this kills all entities.

  • So what you actually want is an expanding square of entities going outwards? – Fabian Röling Feb 19 at 15:15
  • Well if the entity with the tag of B.Cell is in an oak_log block then it'll spread out, if not its deleted. – Khoeckman Feb 19 at 17:37
  • So your ultimate goal is to implement something similar to Veinminer or TreeCapitator? Nice idea, I'll see if I can come up with a smarter algorithm than just duplicating and killing stuff all the time. This is pretty similar to something I did at work once. – Fabian Röling Feb 19 at 19:31
  • I noticied that sumoning an armorstand with the maker tag makes unless 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 at 3:48
  • 1
    @BrunoRodrigues That is a known bug: bugs.mojang.com/browse/MC-88533 – Fabian Röling Feb 25 at 16:23
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.