
# -> Damage mannequin
damage @s 0.0001 generic_kill at ~ ~ ~

# -> Return if entity has been hurt recently
execute unless data entity @s {HurtTime:10s} run \
    return fail

# -> If player had an empty hand then return
execute unless items entity 00000001-0000-002b-0000-00010000002b contents * run \
    return run \
        function overly_realistic:general/downing/player_corpse/corpse_interactions/corpse_hit/no_item_hit

# -> If a player didn't use an appropriate item to harvest the corpse then return
execute as 00000001-0000-002b-0000-00010000002b \
    unless predicate overly_realistic:player/corpse/player_corpse_harvest_use_tool run \
        return run \
            function overly_realistic:general/downing/player_corpse/corpse_interactions/corpse_hit/no_item_hit

# -> Particles
execute at @s run \
    particle block{block_state:"redstone_block"} ~ ~ ~ 0 0 0 0.1 3 normal @a

# -> Add to PlayerCorpseDamage
scoreboard players add @s OverlyRealistic.World.PlayerCorpseDamage 1

# -> Drop loot
execute at @s run \
    loot spawn ~ ~ ~ loot overly_realistic:player_corpses/player_corpse_harvest

# -> If PlayerCorpseDamage is not over max then return
execute unless score @s OverlyRealistic.World.PlayerCorpseDamage matches 10.. run \
    return fail

# -> Drop head
item replace block -29999985 2 -29999985 container.0 with player_head
data modify block -29999985 2 -29999985 Items[{Slot:0b}].components."minecraft:profile" set from entity @s profile
item replace entity 00000001-0000-002b-0000-00010000002b contents from block -29999985 2 -29999985 container.0
execute at @s \
    as 00000001-0000-002b-0000-00010000002b run \
        loot spawn ~ ~ ~ loot overly_realistic:item_from_slot_sources/item_from_contents

# -> Attempt to drop inventory if possible
execute unless entity @s[tag=OverlyRealistic.Entity.PlayerCorpse_HasDroppedInventory] run \
    function overly_realistic:general/downing/player_corpse/corpse_interactions/corpse_interact/drop_items

# -> Remove corpse
function overly_realistic:general/downing/player_corpse/player_corpse_remove
