I've created a datapack that solves this problem by the @Ferrybig's algorithm but with no redstone, functions only.
Setup
First of all, it creates a scoreboard that will be displayed at the sidebar.
setup.mcfunction
scoreboard objectives add area_counter dummy
scoreboard objectives setdisplay sidebar area_counter
Main
Next, we need to set the initial value of the main counter variable. The only way to loop a mcfunction code fragment I know is by recursion, so we create another function count_area
.
NB. I replaced most armor_stand
with area_effect_cloud
for optimization.
main.mcfunction
scoreboard players set count area_counter 0
execute as @e[tag=,type=minecraft:armor_stand] at @s run summon minecraft:area_effect_cloud ~ ~ ~ {Tags:[filled], Duration:1000}
execute as @e[tag=filled,type=minecraft:area_effect_cloud] at @s if block ~ ~-1 ~ minecraft:red_wool run function ac:count_area
execute as @e[tag=filled,type=minecraft:area_effect_cloud] run scoreboard players add count area_counter 1
kill @e[tag=filled,type=minecraft:area_effect_cloud]
Count_area
This is the most difficult part of the solution. First, we set the initial values for following variables:
count_area.mcfunction. 1/3
scoreboard players set has_been_executed area_counter 0
scoreboard players set north area_counter 0
scoreboard players set south area_counter 0
scoreboard players set east area_counter 0
scoreboard players set west area_counter 0
Next, we check every cardinal direction for red wool block exactly like in @Ferrybig's answer.
count_area.mcfunction. 2/3
execute store success score north area_counter as @e[type=minecraft:area_effect_cloud,tag=filled] at @s positioned ~ ~ ~-1 unless entity @e[type=minecraft:area_effect_cloud,tag=filled,distance=...9] if block ~ ~-1 ~ minecraft:red_wool run summon minecraft:area_effect_cloud ~ ~ ~ {Tags:[filled], Duration:1000}
execute store success score south area_counter as @e[type=minecraft:area_effect_cloud,tag=filled] at @s positioned ~ ~ ~1 unless entity @e[type=minecraft:area_effect_cloud,tag=filled,distance=...9] if block ~ ~-1 ~ minecraft:red_wool run summon minecraft:area_effect_cloud ~ ~ ~ {Tags:[filled], Duration:1000}
execute store success score east area_counter as @e[type=minecraft:area_effect_cloud,tag=filled] at @s positioned ~1 ~ ~ unless entity @e[type=minecraft:area_effect_cloud,tag=filled,distance=...9] if block ~ ~-1 ~ minecraft:red_wool run summon minecraft:area_effect_cloud ~ ~ ~ {Tags:[filled], Duration:1000}
execute store success score west area_counter as @e[type=minecraft:area_effect_cloud,tag=filled] at @s positioned ~-1 ~ ~ unless entity @e[type=minecraft:area_effect_cloud,tag=filled,distance=...9] if block ~ ~-1 ~ minecraft:red_wool run summon minecraft:area_effect_cloud ~ ~ ~ {Tags:[filled], Duration:1000}
Finally, we sum every successful summoning to the has_been_executed
and check for it actually has. If it has, the function runs itself.
count_area.mcfunction. 3/3
scoreboard players operation has_been_executed vars += north area_counter
scoreboard players operation has_been_executed vars += south area_counter
scoreboard players operation has_been_executed vars += east area_counter
scoreboard players operation has_been_executed vars += west area_counter
execute unless score has_been_executed area_counter matches 0 run function ac:count_area