
# -> If player has no items then return
scoreboard players set #or.player_inventory_count_item_drop_0 OverlyRealistic.General.ArbitraryData 0
scoreboard players set #or.player_inventory_count_item_drop_1 OverlyRealistic.General.ArbitraryData 0
execute store result score #or.player_inventory_count_item_drop_0 OverlyRealistic.General.ArbitraryData \
    if items entity @s container.* *
execute store result score #or.player_inventory_count_item_drop_1 OverlyRealistic.General.ArbitraryData \
    if items entity @s weapon.offhand *

scoreboard players operation #or.player_inventory_count_item_drop_0 OverlyRealistic.General.ArbitraryData += #or.player_inventory_count_item_drop_1 OverlyRealistic.General.ArbitraryData

execute store result score #or.player_inventory_count_item_drop_1 OverlyRealistic.General.ArbitraryData \
    if items entity @s armor.* *

scoreboard players operation #or.player_inventory_count_item_drop_0 OverlyRealistic.General.ArbitraryData += #or.player_inventory_count_item_drop_1 OverlyRealistic.General.ArbitraryData

execute unless score #or.player_inventory_count_item_drop_0 OverlyRealistic.General.ArbitraryData matches 1.. run \
    return fail

# --> First half

# -> Set box
data remove block -29999987 1 -29999987 Items
setblock -29999987 1 -29999987 minecraft:yellow_shulker_box
#summon item ~ ~-3 ~ {Item:{id:"shulker_box",count:1},Tags:["OverlyRealistic.Player.ItemDrop"]}

# -> Get player inventory
data modify block -29999987 1 -29999987 Items set from storage overly_realistic:player_general dead_player_data.Inventory

# -> Create item
summon item ~ ~ ~ {Tags:["OverlyRealistic.Player.PlayerInventoryHolder0"],Item:{id:"minecraft:stick",count:1}}
execute as @n[type=item,tag=OverlyRealistic.Player.PlayerInventoryHolder0] run \
    function overly_realistic:general/downing/death_item_drop/item_create_0

# --> Other half

# -> Set box
data remove block -29999987 1 -29999987 Items
setblock -29999987 1 -29999987 minecraft:yellow_shulker_box

# -> Get player inventory
item replace block -29999987 1 -29999987 container.0 from entity @s inventory.18
item replace block -29999987 1 -29999987 container.1 from entity @s inventory.19
item replace block -29999987 1 -29999987 container.2 from entity @s inventory.20
item replace block -29999987 1 -29999987 container.3 from entity @s inventory.21
item replace block -29999987 1 -29999987 container.4 from entity @s inventory.22
item replace block -29999987 1 -29999987 container.5 from entity @s inventory.23
item replace block -29999987 1 -29999987 container.6 from entity @s inventory.24
item replace block -29999987 1 -29999987 container.7 from entity @s inventory.25
item replace block -29999987 1 -29999987 container.8 from entity @s inventory.26

item replace block -29999987 1 -29999987 container.9 from entity @s armor.head
item replace block -29999987 1 -29999987 container.10 from entity @s armor.chest
item replace block -29999987 1 -29999987 container.11 from entity @s armor.legs
item replace block -29999987 1 -29999987 container.12 from entity @s armor.feet

item replace block -29999987 1 -29999987 container.13 from entity @s weapon.offhand

# -> Create item
summon item ~ ~ ~ {Tags:["OverlyRealistic.Player.PlayerInventoryHolder1"],Item:{id:"minecraft:stick",count:1}}
execute as @n[type=item,tag=OverlyRealistic.Player.PlayerInventoryHolder1] run \
    function overly_realistic:general/downing/death_item_drop/item_create_0

# -> Store data holder
item replace entity 00000001-0000-002b-0000-00010000002b contents from entity @s armor.body

# -> Clear inventory
clear @s

# -> Return data holder
item replace entity @s armor.body from entity 00000001-0000-002b-0000-00010000002b contents
