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


# Init
execute if data entity @s SelectedItem.components."minecraft:custom_data"{book:true} run scoreboard players set @s temp.data_api.store 0
execute unless score @s temp.data_api.store matches 0.. run scoreboard players set @s temp.data_api.store 1

# Check Hand
$execute if data entity @s[scores={temp.data_api.store=0}] SelectedItem.components."minecraft:custom_data"{book:true} run function data_api:item/tags/book/insert {hand:"weapon.mainhand", slot:"$(slot)"}
$execute if data entity @s[scores={temp.data_api.store=1}] Inventory[{Slot:-106b}].components."minecraft:custom_data"{book:true} run function data_api:item/tags/book/insert {hand:"weapon.offhand", slot:"$(slot)"}
