# Dirt (and dirt-family failsafe starter)
# If sand streak was active, switching ends it.
execute if score FS bc_fs_state matches 2 run scoreboard players set FS bc_fs_state 3

# If already obtained once, do nothing (failsafe expansions are handled by mined-stats tick)
execute if data storage bordercraft:once {item:{dirt:1b}} run return 0

data modify storage bordercraft:once item.dirt set value 1b
scoreboard players add @s bc_contrib_items 1
scoreboard players add @s bc_contrib_total 1
scoreboard players add Items/1674 bc_side 1

# If this is the first qualifying unique item obtained in the world, start the dirt streak.
# Initialize mined-stat prevs first so we don't award bonus expansions for the same initial break.
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_md_prev = @s bc_mined_dirt
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_mg_prev = @s bc_mined_grass_block
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_mp_prev = @s bc_mined_podzol
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_mm_prev = @s bc_mined_mycelium
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_mf_prev = @s bc_mined_farmland
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_mdp_prev = @s bc_mined_dirt_path
execute if score FS bc_fs_state matches 0 run scoreboard players operation @s bc_ms_prev = @s bc_mined_sand

execute if score FS bc_fs_state matches 0 run scoreboard players set FS bc_fs_state 1
execute if score FS bc_fs_state matches 1 if score FS bc_fs_count matches 0.. run scoreboard players set FS bc_fs_count 0

# Mark this unique expansion as a "dirt-type" event for the failsafe gating in bordercraft:expand
data modify storage bordercraft:ctx fs_keep set value 1b
data modify storage bordercraft:ctx cause set value {"translate":"block.minecraft.dirt"}
data modify storage bordercraft:ctx cause_set set value 1b
function bordercraft:expand
data remove storage bordercraft:ctx fs_keep
