#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
#  This Datapack was generated for private distribution only  #
# ----------------------------------------------------------- #
#                         DATAPACK INFO                       #
# ----------------------------------------------------------- #
#     Author: GenMode                                         #
#     Twitter: @DatapackGen                                   #
#     URL: https://github.com/GenMode/Minecraft/wiki          #
#                                                             #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#


# Init
summon minecraft:armor_stand ~ -100 ~ {Tags:["temp.data_api.item"]}

# Modify Data
$item replace block ~ ~ ~ container.$(slot) with minecraft:book
$item replace entity @n[type=minecraft:armor_stand, tag=temp.data_api.item] armor.head from entity @s $(hand)
data modify entity @n[type=minecraft:armor_stand, tag=temp.data_api.item] ArmorItems[3].count set value 1
$data modify block ~ ~ ~ Items[{Slot:$(slot)b}] merge from entity @n[type=minecraft:armor_stand, tag=temp.data_api.item] ArmorItems[3]

# Playsound
execute store result score *pitch temp.data_api.store run random value 0..2
execute as @n[type=minecraft:armor_stand, tag=temp.data_api.item] if data entity @s ArmorItems[3].components."minecraft:enchantments" run function data_api:item/tags/book/playsound {sound:"minecraft:block.chiseled_bookshelf.insert.enchanted"}
execute as @n[type=minecraft:armor_stand, tag=temp.data_api.item] unless data entity @s ArmorItems[3].components."minecraft:enchantments" if data entity @s ArmorItems[3].components."minecraft:enchantment_glint_override" run function data_api:item/tags/book/playsound {sound:"minecraft:block.chiseled_bookshelf.insert.enchanted"}
execute as @n[type=minecraft:armor_stand, tag=temp.data_api.item] unless data entity @s ArmorItems[3].components."minecraft:enchantments" unless data entity @s ArmorItems[3].components."minecraft:enchantment_glint_override" run function data_api:item/tags/book/playsound {sound:"minecraft:block.chiseled_bookshelf.insert"}

# Close
$item modify entity @s $(hand) data_api:set_count/remove_1
kill @e[type=minecraft:armor_stand, tag=temp.data_api.item]
