
# -> Reset score
scoreboard players reset @s OverlyRealistic.Player.UsedAllaySpawn

# -> Reset adv trigger
advancement revoke @s only overly_realistic:blocks/place_custom_block

# -> Store item used
execute if items entity @s weapon.mainhand allay_spawn_egg run \
    item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.mainhand
execute if items entity @s weapon.offhand allay_spawn_egg \
    unless items entity @s weapon.mainhand allay_spawn_egg run \
        item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s weapon.offhand

# -> If block placed requires rotation, get player rotation
execute if items entity 00000001-0000-002b-0000-00010000002b contents *[custom_data~{or_custom_block_require_rotation_0:1b}] run \
    function overly_realistic:general/custom_blocks/general/player_get_rotation

# -> Tag player
tag @s add OverlyRealistic.Player.PlacedCustomBlock

# -> Operate on marker
execute as @n[type=marker,tag=OverlyRealistic.Block.IsCustomBlockMarker,distance=..64] at @s \
    align xyz \
    positioned ~0.5 ~0.5 ~0.5 run \
        function overly_realistic:general/custom_blocks/general/place_custom_block_from_marker with entity @s data

# -> Untag player
tag @s remove OverlyRealistic.Player.PlacedCustomBlock
