
# -> Restore genes
#function overly_realistic:main/debug/death_inventories/data_returnal_attributes/restoration_start
#scoreboard players operation @s OverlyRealistic.Player.Stats.MaxStamina = #or.restorable_death_stats_maxstamina OverlyRealistic.General.ArbitraryData

#scoreboard players operation @s OverlyRealistic.Player.Genetics.AttackDamage = #or.restorable_death_genes_attackdamage OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.AttackSpeed = #or.restorable_death_genes_attackspeed OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.BlockBreakSpeed = #or.restorable_death_genes_blockbreakspeed OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.EntityBlockInteractionRange = #or.restorable_death_genes_entityblockinteractionrange OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.MaxHealth = #or.restorable_death_genes_maxhealth OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.MovementSpeed = #or.restorable_death_genes_movementspeed OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.Scale = #or.restorable_death_genes_scale OverlyRealistic.General.ArbitraryData
#scoreboard players operation @s OverlyRealistic.Player.Genetics.SneakingSpeed = #or.restorable_death_genes_sneakingspeed OverlyRealistic.General.ArbitraryData

# -> 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


# --> Part I

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

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

# -> Slot restoration
item replace entity @s hotbar.0 from block -29999987 1 -29999987 container.0
item replace entity @s hotbar.1 from block -29999987 1 -29999987 container.1
item replace entity @s hotbar.2 from block -29999987 1 -29999987 container.2
item replace entity @s hotbar.3 from block -29999987 1 -29999987 container.3
item replace entity @s hotbar.4 from block -29999987 1 -29999987 container.4
item replace entity @s hotbar.5 from block -29999987 1 -29999987 container.5
item replace entity @s hotbar.6 from block -29999987 1 -29999987 container.6
item replace entity @s hotbar.7 from block -29999987 1 -29999987 container.7
item replace entity @s hotbar.8 from block -29999987 1 -29999987 container.8

item replace entity @s inventory.0 from block -29999987 1 -29999987 container.9
item replace entity @s inventory.1 from block -29999987 1 -29999987 container.10
item replace entity @s inventory.2 from block -29999987 1 -29999987 container.11
item replace entity @s inventory.3 from block -29999987 1 -29999987 container.12
item replace entity @s inventory.4 from block -29999987 1 -29999987 container.13
item replace entity @s inventory.5 from block -29999987 1 -29999987 container.14
item replace entity @s inventory.6 from block -29999987 1 -29999987 container.15
item replace entity @s inventory.7 from block -29999987 1 -29999987 container.16
item replace entity @s inventory.8 from block -29999987 1 -29999987 container.17

item replace entity @s inventory.9 from block -29999987 1 -29999987 container.18
item replace entity @s inventory.10 from block -29999987 1 -29999987 container.19
item replace entity @s inventory.11 from block -29999987 1 -29999987 container.20
item replace entity @s inventory.12 from block -29999987 1 -29999987 container.21
item replace entity @s inventory.13 from block -29999987 1 -29999987 container.22
item replace entity @s inventory.14 from block -29999987 1 -29999987 container.23
item replace entity @s inventory.15 from block -29999987 1 -29999987 container.24
item replace entity @s inventory.16 from block -29999987 1 -29999987 container.25
item replace entity @s inventory.17 from block -29999987 1 -29999987 container.26

# -> Data removal
data modify storage overly_realistic:player_general temp_player_data_restoration.Inventory set from storage overly_realistic:player_general restorable_deaths.Inventory

data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]
data remove storage overly_realistic:player_general restorable_deaths.Inventory[0]

# -> Debug
#data modify storage test_removal Inventory set from storage overly_realistic:player_general temp_player_data_restoration.Inventory
#tellraw @a {color:"blue",storage:"overly_realistic:player_general",nbt:"restorable_deaths.Inventory"}

# --> Part II

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

# -> Get player inventory
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:27b}].Slot set value 0b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:28b}].Slot set value 1b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:29b}].Slot set value 2b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:30b}].Slot set value 3b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:31b}].Slot set value 4b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:32b}].Slot set value 5b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:33b}].Slot set value 6b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:34b}].Slot set value 7b
data modify storage overly_realistic:player_general restorable_deaths.Inventory[{Slot:35b}].Slot set value 8b

data modify block -29999987 1 -29999987 Items set from storage overly_realistic:player_general restorable_deaths.Inventory

#tellraw @a {color:"red",storage:"overly_realistic:player_general",nbt:"restorable_deaths.Inventory"}

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

# -> Data restore
data modify storage overly_realistic:player_general restorable_deaths.Inventory set from storage overly_realistic:player_general temp_player_data_restoration.Inventory

# --> Part III

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

# -> Get & restore player equipment
item replace block -29999987 1 -29999987 container.0 with dirt[custom_data={or_filler_item:"dirt_restore"}]
data modify block -29999987 1 -29999987 Items[0] set from storage overly_realistic:player_general restorable_deaths.equipment.head
item replace entity @s armor.head from block -29999987 1 -29999987 container.0

item replace block -29999987 1 -29999987 container.0 with dirt[custom_data={or_filler_item:"dirt_restore"}]
data modify block -29999987 1 -29999987 Items[0] set from storage overly_realistic:player_general restorable_deaths.equipment.chest
item replace entity @s armor.chest from block -29999987 1 -29999987 container.0

item replace block -29999987 1 -29999987 container.0 with dirt[custom_data={or_filler_item:"dirt_restore"}]
data modify block -29999987 1 -29999987 Items[0] set from storage overly_realistic:player_general restorable_deaths.equipment.legs
item replace entity @s armor.legs from block -29999987 1 -29999987 container.0

item replace block -29999987 1 -29999987 container.0 with dirt[custom_data={or_filler_item:"dirt_restore"}]
data modify block -29999987 1 -29999987 Items[0] set from storage overly_realistic:player_general restorable_deaths.equipment.feet
item replace entity @s armor.feet from block -29999987 1 -29999987 container.0

item replace block -29999987 1 -29999987 container.0 with dirt[custom_data={or_filler_item:"dirt_restore"}]
data modify block -29999987 1 -29999987 Items[0] set from storage overly_realistic:player_general restorable_deaths.equipment.offhand
item replace entity @s weapon.offhand from block -29999987 1 -29999987 container.0

# -> Remove filler items
clear @s dirt[custom_data~{or_filler_item:"dirt_restore"}]
